Description
Yousef loves playing with functions in his free time. Today, he invents the following function:
Yousef will give you a list of queries, and you need to find the answers for them. For each query, you are given an integer n, and your task is to count the number of integers m in which (0 ≤ m ≤ n) and calc(n, m) is an even number. Can you?
Input
The first line contains an integer T
(
1
≤
T
≤
1
0
5
)
(1 ≤ T ≤ 10^5)
(1 ≤ T ≤ 105) specifying the number of test cases.
Each test case consists of a single line containing an integer n ( 0 ≤ n ≤ 1 0 18 ) (0 ≤ n ≤ 10^{18}) (0 ≤ n ≤ 1018), as described in the problem statement above.
Output
For each test case, print a single line containing the number of integers m in which (0 ≤ m ≤ n) and calc(n, m) is an even number.
Example
Input
2
1
2
Output
0
1
Solution
容易看出这其实就是组合数的杨辉三角表示法,问题转化为有多少
C
n
m
C_{n}^{m}
Cnm的值为偶数
对于组合数 C n m C_{n}^{m} Cnm 若 (n & m) == m ,则其值为奇数
我们算出奇数个数也就算出了偶数个数
Code
int main() {
int T;scanf("%d",&T);
while(T--){
ll n;scanf("%lld",&n);
if(n == 0) {printf("0\n"); continue;}
ll res = 1, tmp = n;
while(tmp){
if(tmp&1) res *= 2;
tmp >>= 1;
}
res = (n + 1) - res;
printf("%lld\n", res);
}
return 0;
}