# Odious number

Odious number is a nonnegative number that has an odd number of 1s in its binary expansion. The first few odious numbers are therefore 1, 2, 4, 7, 8, 11, 13, 14, 16, 19…

Given a number check if its a odious number or not.

Examples :

```Input : 16
Output : Odious Number
Explanation: Binary expansion of 16 = 10000,
having number of 1s =1 i.e odd.

Input : 23
Output :  Not odious number
Explanation: Binary expansion of 23 is 10111,
the number of 1s in this is 4 i.e even.
```

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

1) Count set bits in given number.
2) Return true if the count is odd, false otherwise.

## C++

 `// C/C++ program to check if a number is ` `// Odious Number or not ` `#include ` `using` `namespace` `std; ` `#include ` ` `  `/* Function to get no of set bits in binary ` `   ``representation of passed binary no.  ` `   ``Please refer below for details of this  ` `   ``function :  ` `   ``https://www.geeksforgeeks.org/count-set-bits-in-an-integer/ */` `int` `countSetBits(``int` `n) ` `{ ` `    ``unsigned ``int` `count = 0; ` `    ``while` `(n) ` `    ``{ ` `      ``n &= (n-1) ; ` `      ``count++; ` `    ``} ` `    ``return` `count; ` `} ` ` `  `// Check if number is odious or not ` `int` `checkOdious(``int` `n) ` `{ ` `    ``return` `(countSetBits(n) % 2 == 1); ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` `    ``int` `num = 32; ` `    ``if` `(checkOdious(num)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``; ` `    ``return` `0; ` `} `

## Java

 `// Java program to check if a number is ` `// Odious Number or not ` `import` `java.io.*; ` `import` `java.math.*; ` ` `  `class` `GFG { ` `     `  `    ``/* Function to get no of set bits in binary ` `       ``representation of passed binary no.  ` `       ``Please refer below for details of this  ` `       ``function :  ` `       ``https://www.geeksforgeeks.org/count-set-bits-in-an-integer/ */` `    ``static` `int` `countSetBits(``int` `n) ` `    ``{ ` `        ``int` `count = ``0``; ` `        ``while` `(n!=``0``) ` `        ``{ ` `          ``n &= (n-``1``) ; ` `          ``count++; ` `        ``} ` `        ``return` `count; ` `    ``} ` `      `  `    ``// Check if number is odious or not ` `    ``static` `boolean` `checkOdious(``int` `n) ` `    ``{ ` `        ``return` `(countSetBits(n) % ``2` `== ``1``); ` `    ``} ` `      `  `    ``// Driver Code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` `        ``int` `num = ``32``; ` `        ``if` `(checkOdious(num)) ` `            ``System.out.println(``"Yes"``); ` `        ``else` `            ``System.out.println(``"No"``); ` `    ``} ` `} ` ` `  `/*This code is contributed by Nikita Tiwari.*/`

## Python3

 `# Python 3 program to check if a number is ` `# Odious Number or not ` ` `  `# Function to get no of set bits in binary ` `# representation of passed binary no.  ` `# Please refer below for details of this function :  ` `# https://www.geeksforgeeks.org/count-set-bits-in-an-integer ` `def` `countSetBits(n) : ` `    ``count ``=` `0` `     `  `    ``while` `(n) : ` `        ``n ``=` `n & (n``-``1``)  ` `        ``count ``=` `count ``+` `1` `     `  `    ``return` `count ` ` `  ` `  `# Check if number is odious or not ` `def` `checkOdious(n) : ` `    ``return` `(countSetBits(n) ``%` `2` `=``=` `1``) ` `     `  `# Driver Code ` `num ``=` `32` ` `  `if` `(checkOdious(num)) : ` `    ``print``(``"Yes"``) ` `else` `: ` `    ``print``(``"No"``) ` `     `  ` `  `# This code is contributed by Nikita Tiwari. `

## C#

 `// C# program to check if a number ` `// is Odious Number or not ` `using` `System; ` ` `  `class` `GFG { ` `     `  `    ``/* Function to get no of set bits in  ` `    ``binary representation of passed binary ` `    ``no. Please refer below for details  ` `    ``of this function :  ` `    ``https://www.geeksforgeeks.org/count-set-bits-in-an-integer/ */` `    ``static` `int` `countSetBits(``int` `n) ` `    ``{ ` `        ``int` `count = 0; ` `        ``while` `(n != 0) ` `        ``{ ` `        ``n &= (n - 1) ; ` `        ``count++; ` `        ``} ` `         `  `        ``return` `count; ` `    ``} ` `     `  `    ``// Check if number is odious or not ` `    ``static` `bool` `checkOdious(``int` `n) ` `    ``{ ` `        ``return` `(countSetBits(n) % 2 == 1); ` `    ``} ` `     `  `    ``// Driver Code ` `    ``public` `static` `void` `Main() ` `    ``{ ` `        ``int` `num = 32; ` `        ``if` `(checkOdious(num)) ` `            ``Console.Write(``"Yes"``); ` `        ``else` `            ``Console.Write(``"No"``); ` `    ``} ` `} ` ` `  `/*This code is contributed by vt_m.*/`

## PHP

 ` `

Output :

```Yes
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : Mithun Kumar

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.