OJ-Problems-Source/SDUTOJ/3566.cpp

45 lines
900 B
C++
Raw Normal View History

2016-10-12 21:36:52 +08:00
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int t;
/**
n 0. (++ ++ ==== )
2 0.
1
1 1
1 4
1 13
1 40
1 121
F[ N ] = F [ N -1 ] * 3 +1;
a(n)=(3^(n-1)-1)/2
*/
inline int getTbyte(LL inc)
{
int c=0;
while(inc>0)
{
if(inc&1) ++c;
inc>>=1;
}
return c;
}
int main()
{
scanf("%d",&t);
while(t--)
{
LL inc;
scanf("%lld",&inc);
int n=getTbyte(inc);
if(inc&1 || n == 1)
{
printf("0\n");continue;
}
printf("%lld\n",((LL)pow(3,n-1)-1)/2);
}
return 0;
}