
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Woodall Number in C++
In this problem, we are given a number and our task is to check if the number is Woodall number or not.
Woodall number is a special type of number which is of the form,
Wn = n.2n -1
First 5 Woodall numbers are 1, 7, 23, 63, 159
Let’s take an example to understand the problem,
Input
X = 159
Output
Yes
To solve this problem, we will observe the number, if the number is even then it cannot be Woodall and then check for the number. To check, add the number by 1 and recursively divide the number by 2. after each division count the number of times it is divisible. And at each point check if the count is equal to the number.
Program to show the implementation of our solution,
Example
#include <iostream> using namespace std; bool isWoodallNumber(int x){ if (x % 2 == 0) return false; if (x == 1) return true; x+= 1; int p = 0; while(x%2 == 0){ x = x/2; p++; if (p == x) return true; } return false; } int main() { int x = 1424; cout<<x; (isWoodallNumber(x))?cout<<" is a Woodal Number":cout<<" is not a Woodal Number"; return 0; }
Output
1424 is not a Woodal Number
- Related Articles
- Arithmetic Number in C++
- Abundant Number in C ?
- Adam Number in C++
- Ugly Number in C++
- Additive Number in C++
- Encode Number in C++
- Perfect Number in C++
- Entringer Number in C++
- Eulerian Number in C++
- Narayana number in C++
- Neon Number in C++
- Motzkin number in C++
- Kaprekar Number in C++
- Keith Number in C++
- Refactorable number in C++

Advertisements