HDU 4349 Xiao Ming's Hope 组合数学

来源: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;}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值