Xiao Ming's Hope

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1786    Accepted Submission(s): 1182

Problem Description
Xiao Ming likes counting numbers very much, especially he is fond of counting odd numbers. Maybe he thinks it is the best way to show he is alone without a girl friend. The day 2011.11.11 comes. Seeing classmates walking with their girl friends, he coundn't help running into his classroom, and then opened his maths book preparing to count odd numbers. He looked at his book, then he found a question "C(n,0)+C(n,1)+C(n,2)+...+C(n,n)=?". Of course, Xiao Ming knew the answer, but he didn't care about that , What he wanted to know was that how many odd numbers there were? Then he began to count odd numbers. When n is equal to 1, C(1,0)=C(1,1)=1, there are 2 odd numbers. When n is equal to 2, C(2,0)=C(2,2)=1, there are 2 odd numbers...... Suddenly, he found a girl was watching him counting odd numbers. In order to show his gifts on maths, he wrote several big numbers what n would be equal to, but he found it was impossible to finished his tasks, then he sent a piece of information to you, and wanted you a excellent programmer to help him, he really didn't want to let her down. Can you help him?
 
Input
Each line contains a integer n(1<=n<=108)
 
Output
A single line with the number of odd numbers of C(n,0),C(n,1),C(n,2)...C(n,n).
 
Sample Input
1
2
11
 
Sample Output
2
2
8
 
 

题目大意:给你一个数n,让你求C(n,0)、C(n,1)...C(n,n)这n+1个数中为奇数的个数。

解题思路:用Lucas定理。Lucas定理是用来求 c(n,m) mod p,p是素数的值。我们将n化成二进制串。C(A,B)≡C(a[n],b[n])*C(a[n-1],b[n-1])*C(a[n-2],b[n-2])*...C(a[0]*b[0])%p。这里p是2。如果A为10010。B从0 -> 10010枚举。C(0,1)为0。如果n的二进制串中该位置为0,那么要让C(A,B)%2==1那么,只能让m的二进制对应位置为0,对于n的二进制中为1的位置,m的二进制对应位置为0或1的结果都是1。所以结果就是n的二进制中1的位置取2或1的所有可能。即2^k,k为n的二进制中1的个数。

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int sum=0;
while(n){
if(n&1)
sum++;
n>>=1;
}
printf("%d\n",(int)pow(2,sum));
}
return 0;
}

  

HDU 4349——Xiao Ming's Hope——————【Lucas定理】的更多相关文章

  1. HDU 4349 Xiao Ming's Hope lucas定理

    Xiao Ming's Hope Time Limit:1000MS     Memory Limit:32768KB  Description Xiao Ming likes counting nu ...

  2. HDU 4349 Xiao Ming's Hope [Lucas定理 二进制]

    这种题面真是够了......@小明 题意:the number of odd numbers of C(n,0),C(n,1),C(n,2)...C(n,n). 奇数...就是mod 2=1啊 用Lu ...

  3. hdu 4349 Xiao Ming's Hope lucas

    题目链接 给一个n, 求C(n, 0), C(n, 1), ..........C(n, n)里面有多少个是奇数. 我们考虑lucas定理, C(n, m) %2= C(n%2, m%2)*C(n/2 ...

  4. HDU 4349 Xiao Ming's Hope 找规律

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4349 Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/ ...

  5. HDU 4349 Xiao Ming&#39;s Hope

    非常无语的一个题. 反正我后来看题解全然不是一个道上的. 要用什么组合数学的lucas定理. 表示自己就推了前面几个数然后找找规律. C(n, m) 就是 组合n取m: (m!(n-m!)/n!) 假 ...

  6. hdu 4349 Xiao Ming's Hope 规律

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. HDU 4349 Xiao Ming's Hope 组合数学

    题意:给你n,问在C(n,1),C(n,2)...C(n,n)中有多少个奇数. 比赛的时候打表看出规律,这里给一个数学上的说明. Lucas定理:A,B非负整数,p是质数,A,B化为p进制分别为a[n ...

  8. HDU 4349 Xiao Ming's Hope

    有这样一个性质:C(n,m)%p=C(p1,q1)*C(p2,q2).......%p,其中pkpk-1...p1,qkqk-1...q1分别是n,m在p进制下的组成. 就完了. #include&l ...

  9. 数论(Lucas定理) HDOJ 4349 Xiao Ming's Hope

    题目传送门 题意:求C (n,0),C (n,1),C (n,2)...C (n,n)中奇数的个数 分析:Lucas 定理:A.B是非负整数,p是质数.AB写成p进制:A=a[n]a[n-1]...a ...

随机推荐

  1. 对XML文档进行修改

    怎样对XML文档时行修改.Insus.NET在此举个简单的例子.XML文档,就以这篇博文:http://www.cnblogs.com/insus/p/3274220.html 如果我们想对其中一个节 ...

  2. oracle 闪回区故障

    之前为了验证rman,把数据库改为了归档备份,但闪回区却还是4G,结果自动备份在五一执行了,悲剧,幸好没出门.一顿乱搞,其实走了错误方向.思路: 提示untle free,将数据库闪回区先增加:alt ...

  3. jmeter - 录制web网页

    1.       打开JMeter工具 创建一个线程组(右键点击“测试计划”--->“添加”---->“线程组”) 创建一个http代理服务器(右键点击“工作台”--->“添加”-- ...

  4. opencv-视频分解图片

    1.加载视频2. info信息 3. 解码,parse方法解析视频 4. imshow展示或者保存imread # 视频分解图片 # 1 load 2 info 3 parse 4 imshow im ...

  5. vim与vi操作

    vim是vi发展而来的文本编辑器: vi是最原始的文本编辑器: vi/vim的使用: 有三种模式:命令模式.输入模式.底线命令模式 命令模式: 输入 i 会进入输入模式 输入: 会进入底线命令模式 输 ...

  6. linux服务器后台运行程序

    让程序脱离终端单独运行 nohub ... & 重新连接ssh后,ps ux 可以查看所有后台程序

  7. POJ 3067 Japan (树状数组 && 控制变量)

    题意: 西海岸和东海岸有分别有n (1~n)个和m (1~m)个城市, 两个海岸的城市之间有k条公路连通, 公路会相交, 现在给出城市和公路的信息问你由这些公路组成的复杂交通有多少个交点 (如果两个条 ...

  8. css兼容写法

    css3 1.box-shadow: filter:progid:DXImageTransform.Microsoft.Shadow(color=#,direction=,strength=);/*兼 ...

  9. linux / OS 杀死进程

    1,查询端口 sudo netstat -apn | grep 端口号 2,杀死进程kill -9 应用程序进程id

  10. HTTP无状态协议

    http://baike.baidu.com/view/4551466.htm HTTP协议是无状态协议. 无状态是指协议对于事务处理没有记忆能力.缺少状态意味着如果后续处理需要前面的信息,则它必须重 ...