来源:http://acm.hdu.edu.cn/showproblem.php?pid=4349
题意:求C(n,0),C(n,1),C(n,2)...C(n,n).当中有多少个奇数。
就是求n用二进制表示时,其中1的个数,具体可用lacus定理证明。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <vector>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int tmp=0;
while(n)
{
tmp+=n&1;
n>>=1;
}
int ans=1<<tmp;
printf("%d\n",ans);
}
return 0;
}