Print all bitwise subsets of a number N
Submissions: 529   Accuracy:

57.44%

  Difficulty: Easy   Marks: 2

Given a number N, print all the numbers which are a bitwise subset of the binary representation of N. Bitwise subset of a number N will be the numbers i in the range 0<=i<=N which satisfy the below condition:
N & i == i

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

Output:
For each test case, the output is the space separated integers that satisfy the above condition.

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

Example:
Input

2
5
9
Output
5 4 1 0
9 8 1 0

Explanation:
  For 1st test case:
   
0 & 5 = 0
   1 & 5 = 1
   2 & 5 = 0
   3 & 5 = 1
   4 & 5 = 4
   5 & 5 = 5
  

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

Contributor: Vanshika
Author: Vanshika_pec


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



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

to report an issue on this page.