1862: 我叫叶良辰
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 139 Solved: 23
Submit Status Web Board
Description
果果一直很谦虚,但是良辰还是对他出手了(汗。。
良辰拿出来一个 Pascal 三角形(也叫杨辉三角形。(请不要问是怎么拿出来的。。
我们用一个矩阵来表示 Pascal 三角形
0: C(0, 0)
1: C(1, 0) C(1, 1)
2: C(2, 0) C(2, 1) C(2, 2)
...
其中最左边的数字表示行号。C(x, y) 表示一个组合数,即 x 个元素中取 y 个的方法数。
良辰只有一个问题:Pascal 三角形中的第 n 行有多少个奇数?
这样的问题对于果果来说太水了,于是他把这个问题给了你。
Input
第一行为一个整数 T,表示数据组数。 每组数据只有一行,包含一个整数 n,表示 Pascal 三角形的第 n 行。 T <= 2000,0 <= n <= 2^31。
Output
每组数据输出一行,包含一个整数,表示Pascal 三角形的第 n 行中的奇数个数。
Sample Input
2
0
1
Sample Output
1
2
//一个数学定理:lucas推广,不会的在网上找找。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 110
#define M 1000000007
using namespace std;
int main()
{
ll n;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
int cnt=0;
while(n)
{
if(n&1ll)
cnt++;
n>>=1ll;
}
printf("%lld\n",1ll<<cnt);
}
return 0;
}