BZOJ2982——combination
1、题意:求 C(n,m) % 10007 ,10007是质数咯 n和m < 2000000000
2、分析:这个东西太大了,显然不能用n!的阶乘预处理的方式搞出来,也不能用递推公式搞出来
于是我们直接lucas定理 C(n,m) % MOD = C(n / MOD, m / MOD) * C(n % MOD, m % MOD) % MOD
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 10010
#define MOD 10007
inline int read(){
char ch = getchar(); int x = 0, f = 1;
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while('0' <= ch && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int fac[M], inv[M];
inline void init(){
fac[0] = 1;
for(int i = 1; i < MOD; i ++) fac[i] = fac[i - 1] * i % MOD;
inv[1] = 1;
for(int i = 2; i < MOD; i ++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
inv[0] = 1;
for(int i = 1; i < MOD; i ++) inv[i] = inv[i] * inv[i - 1] % MOD;
}
inline int C(int n, int m){
if(n < m){
return 0;
}
if(n < MOD && m < MOD){
return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
return C(n / MOD, m / MOD) * C(n % MOD, m % MOD) % MOD;
}
int main(){
int T = read();
init();
while(T --){
int n = read(), m = read();
printf("%d\n", C(n, m));
}
return 0;
}
BZOJ2982——combination的更多相关文章
- BZOJ2982: combination Lucas模板
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 734 Solved: 437[Submit][Status][Di ...
- bzoj2982: combination
借(cao)鉴(xi)自popoqqq大爷的lucas定理的写法 #include<cstdio> #include<cstring> #include<cctype&g ...
- bzoj2982: combination(lucas定理板子)
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 664 Solved: 397[Submit][Status][Di ...
- 【题解】 bzoj2982: combination (Lucas定理)
题面戳我 Solution 板子题 Code //It is coded by ning_mew on 7.25 #include<bits/stdc++.h> #define LL lo ...
- bzoj2982: combination(Lucas定理)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- BZOJ2982: combination Lucas
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- 2018.09.14 bzoj2982: combination(Lucas定理)
传送门 貌似就是lucas的板子题啊. 练一练手感觉挺舒服的^_^ 代码: #include<bits/stdc++.h> #define mod 10007 #define ll lon ...
- bzoj2982: combination(lucas)
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- [BZOJ2982]combination Lucas定理
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2982 $C(N,M)\% P = C(N\% P,M\% P) * C(N/P,M/P)\ ...
随机推荐
- Winform窗体的基本控件
一.窗体的事件 每一个窗体都有一个事件,这个窗体加载完成之后执行哪一段代码 位置:(1)右键属性→事件→load 双击进入.(2)双击窗体任意一个位置进入 public partial class F ...
- Redis-基于php简单安装使用
1.下载php相关redis扩展(apache选vc6),下载地址: https://github.com/phpredis/phpredis/downloads 2.修改php.ini,增加下面两项 ...
- 查找数据库中重复的值的数据,having的使用,count(1),sum等聚会函数
通过having代替where来使用count(1),sum()等函数.譬如如下数据id value1 21 32 33 53 6 可以写个语句统计value的分组 在这里,可以省略前面的sum(va ...
- win2008无密码共享
http://jingyan.baidu.com/album/76a7e409dc4b5cfc3a6e1566.html?picindex=15
- React业务实践
总结自:http://reactjs.cn/react/docs/thinking-in-react-zh-CN.html 当接到一个需求时,如何用react来实现? 以下几个步骤做参考. 第一步:把 ...
- 20145233 2016-2017 1 linux题目总结
20145233 2016-2017 1 linux题目总结 第一周考试知识汇总 判断:实验楼环境中所有的默认系统用户名和密码均为 shiyanlou.(x ). 填空:Linux Bash中,Ctr ...
- Caliburn.Micro学习笔记(五)----协同IResult
Caliburn.Micro学习笔记目录 今天说一下协同IResult 看一下IResult接口 /// <summary> /// Allows custom code to execu ...
- 浅谈对Spring Framework的认识
Spring Framework,作为一个应用框架,官方的介绍如下: The Spring Framework provides a comprehensive programming and con ...
- java画图之曲线拖动
目标:在窗体上按下鼠标按键.然后拖动鼠标,在按下和拖动之间绘制曲线 事件机制 事件源对象:窗体 事件监听方法:addMouseListener(MouseListener l);addMouseMot ...
- BLE 蓝牙协议栈开发
1.由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(1) 2.由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(2) 3.由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(3)