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 ...
随机推荐
- MyEclipse启动和运行速度优化
1:去除不需要加载的模块 Windows – Preferences - General - Startup and Shutdown,这个时候在右侧就显示出了Eclipse启动时加载的模块,可以根据 ...
- 关于\t
tail -n 10000 sample_dbl.txt | python sitemap.py | sort -k 1 -t $'\t' | python sitecombiner.py > ...
- ANGULAR 2 FOR REACT DEVELOPERS
Now that Angular 2 is in beta, the time has come for us to drop everything and learn something new, ...
- vs2012+cmake+opencv+opencv unable to find a build program corresponding to "Visual Studio 12 Win64". CMAKE_MAKE_PROGRAM is not set
搜索了下,说什么的都有! 一,提示找不到 cmake-2.8.12.1 的 modles 卸载了cmake后发现 cmd 中的 cmake --version 还是 2.8.11.1 找到是我的cyg ...
- UVALive 6602 Counting Lattice Squares
给定一个n*m的网格,求面积为奇数的正方形有多少个. 首先是n*m个面积为1的,然后剩下的要么是边长为奇数,要么被这样一个奇数边长所包围. 原因如下: 对于一个边长不平行于坐标抽的正方形,其边长一定是 ...
- live555
相关资料: Live555 是一个为流媒体提供解决方案的跨平台的C++开源项目,它实现了对标准流媒体传输协议如RTP/RTCP.RTSP.SIP等的支持.Live555实现 了对多种音视频编码格式的音 ...
- ANDROID_MARS学习笔记_S02_009_Animation_Interpolator
public class MainActivity extends Activity { private Button button = null; private ImageView imageVi ...
- Unicode编码的熟悉与研究过程(内附全部汉字编码列表)
我有一个问题是:是不是会有个别汉字无法在Unicode下表示,这种情况下就不能完全显示了? 各种编码查询表:http://bm.kdd.cc/ ---------------------------- ...
- 对QT的产品,以及QT的一些综合评论 good
QT你不能说他不流行吧, WPS, Wirshark, KDE, dropbox, skype, virtualbox都和qt有关吧, 你想写个跨平台的C++程序, QT是个不错的选择, 普通PC应用 ...
- PHP ‘asn1_time_to_time_t’函数内存损坏漏洞
漏洞名称: PHP ‘asn1_time_to_time_t’函数内存损坏漏洞 CNNVD编号: CNNVD-201312-348 发布时间: 2013-12-18 更新时间: 2013-12-18 ...