第一行有一个整数t,代表接下来会有几个a
接下来t行,每行一个非负整数a(a的值不超过230-1),你需要计算每一个a能解出多少个非负整数x
a二进制下所包含1的个数cnt
2cnt即为结果 可以快速幂 O(logn) 速度快
&二进制下末尾1的个数 or 判断奇偶性
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cctype>
using namespace std;
#define PI acos(-1.0)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF32M=0x3f3f3f3f;
const ll INF64M=0x3f3f3f3f3f3f3f3f;
const int maxn=1e5+5;
//特点 快 求可爆int下a^b
ll quickpow(ll x,ll y) //2^29 a二进制下最多29个1 不爆int ll具有普遍性
{
ll ans=1;
while(y) //y=11=1011 x^11
{
if(y&1)
ans=ans*x;
x=x*x; //x^1*x^2*x^8 a^b b个a相乘 O(b)=O(n) x^11 11次
y>>=1; //快速幂 3次 log11=3
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
int T,t,n;
cin>>T;
while(T--)
{
n=0; //每一组数据 2进制下1的个数清0
cin>>t;
while(t!=0) //t二进制下1的个数
{
if(t&1)
{
n++;
}
t>>=1;
}
cout<<quickpow(2,n)<<endl; //cnt最大为29 int int 返回ll
//2^30-1 1后30个0 29个1
}
return 0;
}