HDU4349--Xiao Ming's Hope(数论)
输入一个n(1<=n<=108),求C(n,0),C(n,1),C(n,2)...C(n,n)有多少个奇数。
Lacus定理 http://blog.csdn.net/acm_cxlove/article/details/7844973
A、B是非负整数,p是质数。AB写成p进制:A=a[n]a[n-1]...a[0],B=b[n]b[n-1]...b[0]。
则组合数C(A,B)与C(a[n],b[n])*C(a[n-1],b[n-1])*...*C(a[0],b[0]) modp同
所以此题中 C(n, x) 将n和x化成2进制 C(0,0)=1,C(0,1)=0,C(1,0)=1,C(1,1)=1
所以如果C(n,x)为1,那么n为0的位置x必为0,n为1的位置x为0或1
答案为2^(n的二进制表示1的个数)
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; int main()
{
int n, c;
while (~scanf("%d", &n)) {
c = 0;
while (n) {
if (n & 1) ++c;
n >>= 1;
}
printf("%d\n", (int)pow(2, c));
}
return 0;
}
HDU4349--Xiao Ming's Hope(数论)的更多相关文章
- Hdu4349 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 lucas定理
Xiao Ming's Hope Time Limit:1000MS Memory Limit:32768KB Description Xiao Ming likes counting nu ...
- HDU 5433 Xiao Ming climbing dp
Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...
- hdu 5433 Xiao Ming climbing(bfs+三维标记)
Problem Description Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can ...
- 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 5433 Xiao Ming climbing 动态规划
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5433 Xiao Ming climbing Time Limit: 2000/1000 MS (Ja ...
- 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) ...
- 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/ ...
- hdu5433 Xiao Ming climbing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission ...
- 数论(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 ...
随机推荐
- 产生一个长度为100的int数组,并向其中随机插入1-100,不能重复
]; ArrayList myList=new ArrayList(); Random rnd=new Random(); ) { ,); if(!myList.Contains(num)) myLi ...
- Unity3d Shader开发(三)Pass(Pass Tags,Name,BindChannels )
Pass Tags 通过使用tags来告诉渲染引擎在什么时候该如何渲染他们所期望的效果. Syntax 语法 Tags { "TagName1" = "Value1&qu ...
- JS & DOM 对象
22:36 2013/6/4 详情参照W3C文档标准 Browser 对象(顶层对象) DOM Window DOM Navigator DOM Screen DOM History DOM Loca ...
- input标签文字点击变颜色
<input type="text" class="ser_input"value="从这里搜索(^_^)" onfocus=&quo ...
- oracle dblink 配置两个ip
create database link test_link connect to xx identified by xx using '(DESCRIPTION = (ADDRESS_LIST = ...
- 在C#中关于excel的导入和导出操作
一.先来看看最常见的导入操作吧! private void Import() { //打开excel选择框 OpenFileDialog frm = new OpenFileDialog(); frm ...
- Android:一个高效的UI才是一个拉风的UI(一)
开篇 Android是一个运行在移动终端上的操作系统,跟传统PC最大的不同所在就是移动终端的资源紧缺问题“比较”明显,当然对于一些屌丝机型,应该用“非常“来形容才靠谱.所以经常会出现在一些比较缺乏青春 ...
- Bootstrap 貌似不错,先做一下记录
Bootstrap 简洁.直观.强悍的前端开发框架,让web开发更迅速.简单. http://www.bootcss.com/
- 【 NOIP2015 DAY1 T2 信息传递】带权并查集
题目描述 有n个同学(编号为1到n)正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为i的同学的信息传递对象是编号为Ti同学. 游戏开始时,每人都只知道自己的生日.之后每一 ...
- mysql查看'datadir'目录
mysql查看创建的数据库的数据,包含表等存放的目录,可以输入下面指令查看: show variables like 'datadir'