数论(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[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]) 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;
}
数论(Lucas定理) HDOJ 4349 Xiao Ming's Hope的更多相关文章
- CPC23-4-K. 喵喵的神数 (数论 Lucas定理)
喵喵的神∙数 Time Limit: 1 Sec Memory Limit: 128 MB Description 喵喵对组合数比較感兴趣,而且对计算组合数很在行. 同一时候为了追求有后宫的素养的生活 ...
- 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:1000MS Memory Limit:32768KB Description Xiao Ming likes counting nu ...
- 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 [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 lucas
题目链接 给一个n, 求C(n, 0), C(n, 1), ..........C(n, n)里面有多少个是奇数. 我们考虑lucas定理, C(n, m) %2= C(n%2, m%2)*C(n/2 ...
- Bzoj 4591: [Shoi2015]超能粒子炮·改 数论,Lucas定理,排列组合
4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 178 Solved: 70[Submit][Stat ...
- HDU 4349 Xiao Ming's Hope
非常无语的一个题. 反正我后来看题解全然不是一个道上的. 要用什么组合数学的lucas定理. 表示自己就推了前面几个数然后找找规律. C(n, m) 就是 组合n取m: (m!(n-m!)/n!) 假 ...
- hdu 4349 Xiao Ming's Hope 规律
Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- vi/vim 消除搜索后的关键字高亮
使用vi或vim命令搜索某个关键字之后,取消高亮显示的方法 只要输入:noh即可
- Visual Studio 2015 开发 ASP.NET 5 有何变化?(转)
出处:http://www.cnblogs.com/xishuai/p/visual-studio-2015-preview-asp-net-5-change.html 本篇博文目录: ASP.NET ...
- 38 写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。
题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度. public class _038PrintLength { public static void main(Stri ...
- 从命令行运行 MyBatis Generator
? ? 一.准备 1. 获取最新jar包 2. 获取xml dtd <?xml version="1.0" encoding="UTF-8"?> & ...
- [转][译] 存储引擎原理:LSM
原译文地址:http://www.tuicool.com/articles/qqQV7za http://www.zhihu.com/question/19887265 http://blog.csd ...
- 公司web安全等级提升
目录 背景介绍 目录 针对国调的初次测试结果 解决方案 二次测试 关于XSS 什么是XSS 基本防御 代码防御 xss代码辑录 说明 参考文章 版本记录 背景介绍 公司的一个web数据展示系统,本来是 ...
- 编写高质量代码改善C#程序的157个建议——建议125:避免用FCL的类型名称命名自己的类型
建议125:避免用FCL的类型名称命名自己的类型 试想过自己写一个Socket类型吗?如果没有,我们来尝试一下: public class Socket { //省略 } 把以上代码同某些其他工具类封 ...
- mybatis SqlMapConfig.xml
一.SqlMapConfig.xml 1.属性properties 在入门时,以抽取出连接数据库的属性得到properties文件. a.可以通过resource和url来获得属性. b.proper ...
- 'System.ValueTuple, Version=0.0.0.0 required for Add-Migration on .NET 4.6.1 Class Library
https://stackoverflow.com/questions/45978173/system-valuetuple-version-0-0-0-0-required-for-add-migr ...
- json 登陆协议分析
登录方式有两种:1)用户名密码登陆,code 为 5401 (2) IMSI和TOKEN 登陆, code 为93 POST /tcpbus/mobile HTTP/1.1Host: clientac ...