HDU 4349——Xiao Ming's Hope——————【Lucas定理】
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
题目大意:给你一个数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定理】的更多相关文章
- HDU 4349 Xiao Ming's Hope lucas定理
Xiao Ming's Hope Time Limit:1000MS Memory Limit:32768KB Description Xiao Ming likes counting nu ...
- 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 ...
- 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 ...
- 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/ ...
- HDU 4349 Xiao Ming's Hope
非常无语的一个题. 反正我后来看题解全然不是一个道上的. 要用什么组合数学的lucas定理. 表示自己就推了前面几个数然后找找规律. C(n, m) 就是 组合n取m: (m!(n-m!)/n!) 假 ...
- hdu 4349 Xiao Ming's Hope 规律
Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 ...
- 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 ...
- 数论(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 ...
随机推荐
- 【C#】EF学习<一> CodeFist
[第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) 目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) http://www.cnblogs.com/ ...
- JavaFx 实现画图工具
制作一款类似于Windows画图工具程序 功能需求: (1)在画布上绘制直线.曲线.矩形.椭圆等图形 (2)实现输入文字,橡皮擦 (3)可以绘制填充图形以及设置画笔的颜色和粗细 (4)实现撤销操作.保 ...
- Go语言学习教程:xorm表基本操作及高级操作
在上节内容中,我们介绍了xorm框架表结构的映射规则和表结构的操作.本节课,继续来深入学习表结构基本操作和高级查询的相关功能. 表结构基本操作 对表结构的操作最常见的操作是查询和统计相关的方法,我们首 ...
- 线段树 SP1043 GSS1 - Can you answer these queries I
SP1043 GSS1 - Can you answer these queries I 题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义 ...
- 10.11cdy考试题
鸣谢cdy math [题目描述] 众所周知, xkj是GH的得意门生, 可是xkj的数学成绩并不是很理想: 每次GH在批评完数学限训做的差的人时, 总会在后面加一句:咱们班还有一位做的最差的同学-- ...
- 「产品经理全连接系列1」Epic/Feature/Story/Task/Bug到底是什么
大家好,我是华为云的产品经理 恒少: 作为布道师和产品经理,出差各地接触客户是常态,经常和华为云的客户交流.布道.技术沙龙,但是线下交流,覆盖的用户总还是少数. 我希望可以借线上的平台,和用户持续交流 ...
- const常量,常量折叠,字面常量
const int a=10: 涉及到一个叫常量折叠的概念(认为我这说得太简单或者不好理解的可以google一下它获取更多信息), 即编译器虽然会给a分配空间(如果取a的地址进行操作的时候,会强迫编译 ...
- springcloud系列四 搭建服务模块重点讲解
首先这个服务地址:一定不要写错,是自己注册中心开启的地址 如果注意到这些了,可以简单的进行操作,也可以不需要mybatis与数据库连接,在controller里直接返回相应的数据可以了,不用这么幸苦的 ...
- 本地命令上传文件到服务器以及linux编辑过程中非正常退出问题
一.上传文件到linux服务器首先从你本地切换到你要上传文件的目录,接下来:scp 文件名字 服务器用户名字@服务器ip:存储路径例子:scp index.html root@106.75.229 ...
- gitflow工作流简介
gitflow工作流是一种依赖于Git版本管理工具,按特定规范对项目开发.测试.上线流程进行管理的工作方式.它是一种为实现规范化管理的约定,它明确了各个分支的意义,使整个团队的分工协作更加和谐明晰. ...