Number is sparse or not
Submissions: 4500   Accuracy:

59.59%

  Difficulty: Basic   Marks: 1

Given a number N, check whether it is sparse or not. A number is said to be a sparse number if in the binary representation of the number no two or more consecutive bits are set.

Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is number 'N'.

Output:
Print '1' if the number is sparse and '0' if the number is not sparse.

Constraints:
1 <= T <= 100
1 <= N <= 103

Example:
Input:
2
2
3

Output:
1
0

Explanation:
Testcase 1:
Binary Representation of 2 is 10, which is not having consecutive set bits. So, it is sparse number.
Testcase 2: Binary Representation of 3 is 11, which is having consecutive set bits in it. So, it is not a sparse number.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Yash Goel


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.