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. 注意!list和array是不同的

     python中的list是python的内置数据类型,list中的数据类型不必相同的,而array的中的数据类型必须全部相同. numpy中封装的array有很强大的功能,里面存放的都是相同的数据类 ...

  2. scala 操作hdfs

    获取hdfs文件下所有文件getAllFiles 遍历 spark读取 1 package com.spark.demo import java.io.IOException import java. ...

  3. ubuntu 18.04下安装配置HBase问题记录

    参考资料: Ubuntu下HBase安装与使用(shell+Java API) 问题 无法正常启动hbase,在Log里报错java.lang.ClassNotFoundException: org. ...

  4. 单例设计模式 --c#

    单例设计模式:在单例设计模式中我们要保持对象始终是唯一的 参考代码: class SingleObject { private SingleObject() { } private static Si ...

  5. ucos ii 46个系统API函数解析

    源: ucos ii 46个系统API函数解析

  6. django 模型类的常见字段约束,以及filter 过滤和查询

    null 不设置时默认设置为False.设置为True时,数据库表字段中将存入NULL的记录. null和blank组合使用,null=True,blank=True,表示该字段可以为空 blank ...

  7. django模板-if标签和for标签

    在django中,标签写在{%  标签  %}中 if else标签 ①通过if进行条件判断 views.py from django.shortcuts import render def inde ...

  8. Centos部署flask项目

    必备: Python2.7(ok) MySQL(ok) git supervisor virtualenv Gunicorn 阿里云服务器(最便宜的就好) 域名(国内万网,国外goDaddy) 我的P ...

  9. spring List,Set,Map,Properties,array的配置文件注入方式

    虽然不多,但是有时候在实现的时候,我们还是希望某些参数或者属性通过集合()的方式注入进来,比如配置表参数列表,addresslist,亦或是三方库等等.因为这种改动不是很多,经常一时想不起来,今天做个 ...

  10. 使用TortoiseGit从GitHub下拉上传代码配置

    转载:http://baijiahao.baidu.com/s?id=1579466751803515477&wfr=spider&for=pc 转载:https://blog.csd ...