数论(Lucas定理) HDOJ 4349 Xiao Ming's Hope
2015-08-27 19:32
471 查看
题目传送门
题意:求C (n,0),C (n,1),C (n,2)...C (n,n)中奇数的个数
分析:Lucas 定理:A、B是非负整数,p是质数。AB写成p进制:A=a
a[n-1]...a[0],B=b
b[n-1]...b[0]。则组合数C(A,B)与C(a
,b
)*C(a[n-1],b[n-1])*...*C(a[0],b[0]) mod p同。即:Lucas (n,m,p)=C (n%p,m%p) * Lucas (n/p,m/p,p)
我是打表找规律的,就是: 2^二进制下1的个数。这定理可以求C (n, m) % p 详细解释
收获:1. 没思路时一定要打个表找找规律 2. Lucas定理
代码:
题意:求C (n,0),C (n,1),C (n,2)...C (n,n)中奇数的个数
分析:Lucas 定理:A、B是非负整数,p是质数。AB写成p进制:A=a
a[n-1]...a[0],B=b
b[n-1]...b[0]。则组合数C(A,B)与C(a
,b
)*C(a[n-1],b[n-1])*...*C(a[0],b[0]) mod p同。即:Lucas (n,m,p)=C (n%p,m%p) * Lucas (n/p,m/p,p)
我是打表找规律的,就是: 2^二进制下1的个数。这定理可以求C (n, m) % p 详细解释
收获:1. 没思路时一定要打个表找找规律 2. Lucas定理
代码:
/************************************************ * Author :Running_Time * Created Time :2015-8-27 8:48:05 * File Name :J.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int main(void) { int n; while (scanf ("%d", &n) == 1) { int cnt = 0; while (n) { if (n & 1) cnt++; n >>= 1; } ll ans = 1; for (int i=1; i<=cnt; ++i) ans *= 2; printf ("%I64d\n", ans); } return 0; }
相关文章推荐
- Linux学习日记--基础命令(8)--算数运算,条件测试
- GDT、GDTR、LDT、LDTR的理解 [zz]
- 【转】在CentOS上安装tomcat
- linux中root密码忘了怎么办?
- GCD和NSOperation多线程技术
- 【转】CentOS上安装 jdk:rpm安装和源码安装
- Linux用户和用户组以及相关命令(下)
- CentOS6.7 用vmware设置共享,执行mount -t vmhgfs 报错no such device解决办法
- Linux系统管理-系统资源查看
- Linux 删除文件夹和文件的命令
- 理解RESTful架构
- 使用logrotate配置Nginx日志轮替
- 从零单排Opencv---新旧版本函数变化
- linux开机启动步骤
- Linux学习日记--基础命令(7)--bash中的变量,配置文件
- CentOS学习3_CentOS6.5下安装Eclipse
- POJ 3258 River Hopscotch(二分法)
- HDU 4349——Xiao Ming's Hope——————【Lucas定理】
- Archlinux安装与出现的问题
- 19Lync2013升级到SkypeForBusiness2015进阶篇--SFB后端启用Mirror高可用