# Woodall Number

A Woodall number is of the form:

Wn = n.2n – 1

The first few Woodall numbers are: 1, 7, 23, 63, 159, 383, 895……

Given a number X. The task is to check if X is woodall number or not.

Examples:

```Input : X = 383
Output : Yes
For n = 6, Wn = n.2n - 1 = 383.

Input : X = 200
Output : No
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

1. We can observe that all Woodall numbers are odd. So, first of all we check if given number is odd or not.
2. Now to check if number is woodall or not, increment given number by 1 and now divide number by 2 until it is even and count number of times it is divisible. And at each point check if count is equal to number or not.

Below is the implementation of this approach:

## C++

 `// CPP program to check if a number is ` `// Woodball or not. ` `#include ` `using` `namespace` `std; ` ` `  `bool` `isWoodall(``int` `x) ` `{ ` `    ``// If number is even, return false. ` `    ``if` `(x % 2  == 0) ` `        ``return` `false``; ` ` `  `    ``// If x is 1, return true. ` `    ``if` `(x == 1) ` `        ``return` `true``; ` `     `  `    ``x++;  ``// Add 1 to make x even ` ` `  `    ``// While x is divisible by 2 ` `    ``int` `p = 0; ` `    ``while` `(x % 2 == 0) { ` ` `  `        ``// Divide x by 2 ` `        ``x = x/2; ` ` `  `        ``// Count the power ` `        ``p++; ` ` `  `        ``// If at any point power and  ` `        ``// x became equal, return true. ` `        ``if` `(p == x) ` `            ``return` `true``; ` `    ``} ` ` `  `    ``return` `false``; ` `} ` ` `  `// Driven Program ` `int` `main() ` `{ ` `    ``int` `x = 383; ` ` `  `    ``(isWoodall(x)) ? (cout << ``"Yes"` `<< endl) :  ` `                     ``(cout << ``"No"` `<< endl); ` `    ``return` `0; ` `} `

## Java

 `// JAVA program to check if a number ` `// is Woodall or not. ` `class` `GFG { ` `     `  `    ``static` `boolean` `isWoodall(``int` `x) ` `    ``{ ` `        ``// If number is even, return false. ` `        ``if` `(x % ``2`  `== ``0``) ` `            ``return` `false``; ` `      `  `        ``// If x is 1, return true. ` `        ``if` `(x == ``1``) ` `            ``return` `true``; ` `          `  `        ``x++;  ``// Add 1 to make x even ` `      `  `        ``// While x is divisible by 2 ` `        ``int` `p = ``0``; ` `        ``while` `(x % ``2` `== ``0``) { ` `      `  `            ``// Divide x by 2 ` `            ``x = x / ``2``; ` `      `  `            ``// Count the power ` `            ``p++; ` `      `  `            ``// If at any point power and  ` `            ``// x became equal, return true. ` `            ``if` `(p == x) ` `                ``return` `true``; ` `        ``} ` `      `  `        ``return` `false``; ` `    ``} ` `      `  `    ``// Driven Program ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `        ``int` `x = ``383``; ` `      `  `        ``if``(isWoodall(x))  ` `            ``System.out.println(``"Yes"``); ` `        ``else` `            ``System.out.println(``"No"``); ` `    ``} ` `} ` ` `  `/*This code is contributed by Nikita Tiwari.*/`

## Python

 `# Python program to check if a number ` `# is Woodball or not. ` ` `  `def` `isWoodall(x) : ` `     `  `    ``# If number is even, return false. ` `    ``if` `(x ``%` `2`  `=``=` `0``) : ` `        ``return` `False` `  `  `    ``# If x is 1, return true. ` `    ``if` `(x ``=``=` `1``) : ` `        ``return` `True` `      `  `    ``x ``=` `x ``+` `1`  `# Add 1 to make x even ` `  `  `    ``# While x is divisible by 2 ` `    ``p ``=` `0` `    ``while` `(x ``%` `2` `=``=` `0``) : ` `         `  `        ``# Divide x by 2 ` `        ``x ``=` `x``/``2` `  `  `        ``# Count the power ` `        ``p ``=` `p ``+` `1` `  `  `        ``# If at any point power and  ` `        ``# x became equal, return true. ` `        ``if` `(p ``=``=` `x) : ` `            ``return` `True` `         `  `    ``return` `False` `     `  `  `  `# Driven Program ` `x ``=` `383` `if``(isWoodall(x)) : ` `    ``print` `"Yes"` `else`  `: ` `    ``print` `"No"` `     `  `# This code is contributed by Nikita Tiwari. `

## C#

 `// C# program to check if a number ` `// is Woodall or not. ` `using` `System; ` ` `  `class` `GFG { ` `     `  `    ``static` `bool` `isWoodall(``int` `x) ` `    ``{ ` `        ``// If number is even, return false. ` `        ``if` `(x % 2 == 0) ` `            ``return` `false``; ` `     `  `        ``// If x is 1, return true. ` `        ``if` `(x == 1) ` `            ``return` `true``; ` `         `  `        ``x++; ``// Add 1 to make x even ` `     `  `        ``// While x is divisible by 2 ` `        ``int` `p = 0; ` `        ``while` `(x % 2 == 0) { ` `     `  `            ``// Divide x by 2 ` `            ``x = x / 2; ` `     `  `            ``// Count the power ` `            ``p++; ` `     `  `            ``// If at any point power and  ` `            ``// x became equal, return true. ` `            ``if` `(p == x) ` `                ``return` `true``; ` `        ``} ` `     `  `        ``return` `false``; ` `    ``} ` `     `  `    ``// Driver Code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``int` `x = 383; ` `     `  `        ``if``(isWoodall(x))  ` `            ``Console.WriteLine(``"Yes"``); ` `        ``else` `            ``Console.WriteLine(``"No"``); ` `    ``} ` `} ` ` `  `// This code is contributed by Nikita Tiwari. `

## PHP

 ` `

Output:

```Yes
```

This article is contributed by Anuj Chauhan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

My Personal Notes arrow_drop_up

Improved By : vt_m

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.