来源:http://acm.hdu.edu.cn/showproblem.php?pid=4349
题意:求C(n,0),C(n,1),C(n,2)...C(n,n).当中有多少个奇数。
思路:表示比赛时是水过的,求出了前8个数,发现都是2的幂,然后就发现规律了。就是n转化为二进制后又多少个1,就是2的多少次方。解题报告说是Lucas定理,不知道Lucas定理是什么,也没看懂证明。。太弱了
代码:
#include <iostream>#include <cstdio>#include <string.h>using namespace std;int fun(int x){ int s = 0; while(x){ int y = x % 2; if(y) s++; x /= 2; } return s;}__int64 mi(int x){ __int64 s = 1; for(int i = 1; i <= x; ++i) s *= 2; return s;}int main(){ int n; while(scanf("%d",&n) != EOF){ int cnt = fun(n); __int64 ans = mi(cnt); printf("%d\n",ans); } return 0;}