bzoj2982: combination(Lucas定理)
Description
Input
Output
Sample Input
5 1
5 2
7 3
4 2
Sample Output
10
35
6
#include<iostream>
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
int min(int a,int b){return a<b?a:b;}
const int p=1e4+;
int t,n,m,fac[p+];
int Pow(int x,int y){
int res=;
for(;y;y>>=,x=1ll*x*x%p)
if(y&) res=1ll*res*x%p;
return res;
}
int C(int a,int b){
return a<b?:1ll*fac[a]*Pow(fac[b],p-)%p*Pow(fac[a-b],p-)%p;
}
int lucas(int a,int b){
return b?1ll*lucas(a/p,b/p)%p*C(a%p,b%p)%p:;
}
int main(){
scanf("%d",&t); fac[]=;
for(int i=;i<=p;++i) fac[i]=1ll*fac[i-]*i%p;
while(t--){
scanf("%d%d",&n,&m);
printf("%d\n",lucas(n,min(m,n-m)));
}return ;
}
bzoj2982: combination(Lucas定理)的更多相关文章
- bzoj2982: combination(lucas定理板子)
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 664 Solved: 397[Submit][Status][Di ...
- [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)\ ...
- 【BZOJ2982】combination Lucas定理
[BZOJ2982]combination Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然, ...
- ZOJ 3557 & BZOJ 2982 combination[Lucas定理]
How Many Sets II Time Limit: 2 Seconds Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...
- BZOJ2982: combination Lucas模板
2982: combination Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 734 Solved: 437[Submit][Status][Di ...
- bzoj2982 combination——卢卡斯定理
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2982 卢卡斯定理裸题: 原准备1A来着,结果输出忘了加回车! 预处理阶乘或者现求都可以,感觉 ...
- BZOJ2982: combination Lucas
Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...
- BZOJ 2982 combination Lucas定理
题目大意:发上来就过不了审核了--总之大意就是求C(n,m) mod 10007 m,n∈[1,2*10^8] 卢卡斯定理:C(n,m)=C(n%p,m%p)*C(n/p,m/p) mod p 要求p ...
- Lucas定理模板【bzoj2982】【combination】
(上不了p站我要死了,侵权度娘背锅) Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ ...
- 【BZOJ】2982: combination(lucas定理+乘法逆元)
http://www.lydsy.com/JudgeOnline/problem.php?id=2982 少加了特判n<m return 0就wa了QAQ lucas定理:C(n, m)%p=( ...
随机推荐
- ELK之在windows安装filebeat收集日志
登录官方网站下载filebeat的windows客户端 https://www.elastic.co/downloads/beats 下载压缩包,无需解压 修改配置文件filebeat.yml 其余设 ...
- Ucloud云主机无法yum安装处理办法
Ucloud云主机在yum安装的时候出现这个提示 执行一下命令 yum --disablerepo=salttestyum-config-manager --disable salttestyum-c ...
- Saltstack之job管理和runner
Master端执行命令及操作默认会保存在master端的/var/cache/salt/master/jobs 默认保存时间是24小时 如果需要保存在数据库 先参考http://www.cnblogs ...
- 洛谷P2216 理想的正方形
题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入输出格式 输入格式: 第一行为3个整数,分别表示a,b,n的值 第二行至 ...
- 2018-2019-2 20165330《网络对抗技术》Exp2 后门原理与实践
目录 基础问题 相关知识 实验内容 实验步骤 实验过程中遇到的问题 实验总结与体会 实验内容 使用netcat获取主机操作Shell,cron启动 使用socat获取主机操作Shell, 任务计划启动 ...
- 启用mapredure历史服务器方法
在mapred-site.xml配置文件中添加如下信息: <property> <name>mapreduce.jobhistory.addres ...
- MongoDB-3.4安装文档
1.建立目录 2.将解压文件cp到步骤1建立目录下 mongodb-win32-x86_64-enterprise-windows-64-3.4.1.zip 3.配置环境变量 4.启动mongodb服 ...
- python面向对象高级:Mixin多重继承
继上一篇学习笔记:python面向对象的继承与多态,本篇就Mixin扩展类的方法写下学习笔记 Mixin Mixin编程是一种开发模式,是一种将多个类中的功能单元的进行组合的利用的方式,这听起来就像是 ...
- ubuntu 12.10上安装tftpd-hpa
ubuntu 12.10上安装tftpd-hpa 1)安装tftp-hpa,tftpd-hpa sudo apt-get install tftp-hpa tftpd-hpa tftp-hpa是cli ...
- router-link params传参
1.router.js配置 需要在路径后定义上要传的属性名 --> /:属性名(query方式不需要) { path: '/CreateProgress/:name1', name: ...