Given a positive integer N, N please find out the conversion to binary 1 wherein all of the positions. The minimum binary bit (far right) for the first 0.
Input
输入数据 第一行为一个整数m,表示测试用例的个数;接下来有m行,每行表示一个测试用例,
每个测试用例为一个十进制数n,1<=m<=20;1<=n<=2000000000。
Output
输出数据 十进制整数n对应的二进制数中所有1的位置,在一行输出,最低位的位置为0多个测试用例的结果顺序输出,
之间没有空行,整数前不加无效的0,输出两数之间有一个空格,最后没有空格。
Sample Input
2
13
8
Sample Output
0 2 3
3
Hint
参见16123
#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,T;
vector<int>ans;
int main()
{
scanf("%d",&T);
while(T--)
{
ans.clear();
long long n,p=1;
scanf("%lld",&n);
int x=0;
while(n>=p)
{
if(n&p)ans.push_back(x);
x++,p*=2;
}
for(int i=0;i<ans.size();i++)printf("%d%c",ans[i],i==ans.size()-1?'\n':' ');
}
return 0;
}