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, m/2)%2, C(n/2, m/2) = C(n/2%2, m/2%2)*C(n/2/2, m/2/2), 这样一直递归下去,直到m为0。 我们知道如果一个数是奇数, 那么它的所有因子都是奇数, 对应于上面的式子, n%2是偶数的时候, m%2也必须是偶数才可以, 而n%2是奇数的时候, m%2的值则没有要求。 而n/2, 相当于是二进制的n向右移了一位。所以最后的结果相当于是2^num, num是n的二进制中1的个数。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int main()
{
int n;
while(scanf("%d", &n)!=EOF) {
int ans = ;
while(n) {
if(n&)
ans++;
n>>=;
}
printf("%d\n", <<ans);
}
return ;
}
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 找规律
原题链接: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定理】
Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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
非常无语的一个题. 反正我后来看题解全然不是一个道上的. 要用什么组合数学的lucas定理. 表示自己就推了前面几个数然后找找规律. C(n, m) 就是 组合n取m: (m!(n-m!)/n!) 假 ...
- 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 ...
- HDU 5433 Xiao Ming climbing dp
Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...
随机推荐
- 加入收藏夹的js代码(求兼容chrome浏览器的代码)
从网上找了加入收藏夹的js代码,但不兼容chrome,不知道有没有兼容chrome的相关代码,希望有知道的告诉一下,谢谢! 代码如下 $("#id").click(function ...
- mongodb cpu 超过100%居高不下的原因分析过程
-- mongodb cpu is high, infomation as below: 1 the message in the http://10.100.1.11:28017/ as below ...
- java读取TXT文件的方法
java读取txt文件内容.可以作如下理解: 首先获得一个文件句柄.File file = new File(); file即为文件句柄.两人之间连通电话网络了.接下来可以开始打电话了. 通过这条线路 ...
- web - 清除浮动
最理想的方式为 伪类 + content : 例如 div:after{content:"";display:block;clear:both;} div{zoom:1;} 另外, ...
- shell检测interface是否已分配ip,qt调用shell脚本
#include <QCoreApplication>#include <QDebug>#include <QTextStream>#include <QDi ...
- C++_基础_C与C++的区别2
内容: (1)C++中的函数 (2)动态内存 (3)引用 (4)类型转换 (5)C++社区对C程序员的建议 1.C++中的函数1.1 函数的重载(1)重载的概念 在同一个作用域中,函数名相同,函数的参 ...
- day5_python学习笔记_chapter7_字典
1. 内建方法fromkeys()创建一个默认字典, 字典中元素具有相同的值,默认为None dict1 = {}.fromkeys(('x', 'y'), -1) 2. 访问字典中的值, for ...
- Spring集成Quartz定时器
<!-- Spring集成Quartz开始 --> <bean id="startQuertz" lazy-init="false" auto ...
- Chrome设计文档-多进程架构
chromium multi-process architecture 本文档从high-level的角度描述Chromium的多进程架构. 问题 要构建一个决不崩溃或挂起的渲染引擎几乎是不可能的.同 ...
- lock table
1.在执行lock table语句后,则在执行unlock tables之前,当前会话只能操作当前被锁定的表(包括表别名)2.read锁,其它会话只有读取权限,没有写入权限3.write锁,其它会话只 ...