Xiao Ming's Hope

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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
 
Author
HIT
 
Source

题意:C(n,m)表示组合数n个取m的方案数;

   求C(n,0),C(n,1),C(n,2),......C(n,n)有多少个奇数;

思路:打表找规律,

   证明:卢卡斯   

    C(n,m)%p=C(n/p,m/p)*C(n%p,m%p)%p;

   令p等于2,C(n%p,m%p) 为C(1,1),C(1,0),C(0,0),C(0,1) ,

   枚举n的二进制表示每一位数,当前位为1是可以有两种方案;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e2+,M=2e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; int main()
{
int n;
while(~scanf("%d",&n))
{
int ans=;
while(n)
{
if(n&)ans++;
n/=;
}
cout<<(<<ans)<<endl;
}
return ;
}

hdu 4349 Xiao Ming's Hope 规律的更多相关文章

  1. 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/ ...

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

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

  3. 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) ...

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

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

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. HDU 5433 Xiao Ming climbing dp

    Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...

随机推荐

  1. Oracle笔记 #01# 简单分页

    rownum是Oracle为查询结果分配的有序编号(总是从1~n).言下之意,rownum字段本来并不存在于表中,而是经查询后才分配的. 举一个例子: SELECT rownum, name, pri ...

  2. Web开发相关笔记 #04# WebSocket

    本文的主要内容: HTTP VS. WebSocket WebSocket 的客户端实现(JavaScript) WebSocket 的服务端实现(Java & apache WebSocke ...

  3. Linux的远程连接工具:SSH的安装

    在Linux执行命令很不方便,另外我们需要将自己计算机中的文件上传到Linux中,因此使用远程连接工具还是比较方便的. SSH安装 SSH的使用 打开安装好的软件:SSH Secure File Tr ...

  4. twiested 及其他轮子

    https://www.lfd.uci.edu/~gohlke/pythonlibs/

  5. 使用vim打造自己的python编辑器

    基础配置 vim的配置是在用户主目录下的 ~/.vimrc 文件中完成的,如果没有的话,需要自己新建一下: cd ~ touch .vimrc 首先做些简单的配置: set nocompatible ...

  6. win7系统复制文件到u盘提示文件过大怎么办

    转载:https://www.xitmi.com/770.html 系统相信很多朋友都遇到过这种情况,在你拷贝文件到u盘时,u盘剩余空间明明很大,但是却复制不进去,电脑提示“对于目标文件系统 文件过大 ...

  7. 【Python30--文件系统】

    一.模块 定义:模块是一个包含所有定义的函数和变量的文件,后缀名是.py.模块可以被别的程序引用,以使用该模块中的函数等功能 >>> secret = random.randint( ...

  8. python --- 25 模块和包

    一.模块 1.导入方式 自己创建的模块名称 切不可和 内置模块的一样 ①  import  模块 ②  import 模块 as  名      设置在此空间的名称 ③  from 模块 import ...

  9. Eclipse关联Github

    摘自:http://jingyan.baidu.com/article/64d05a0262f013de55f73bcc.html 检查Eclipse中是否已安装Git插件,菜单栏Help -> ...

  10. topcoder srm 360 div1

    problem1 link (1)$n \neq m$时,假设$n<m$,那么同一行中的$m$个数字必定都相等. (2)$n=m$时,要满足任意的$i_{1},i_{2},j_{1},j_{2} ...