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=( ...
随机推荐
- Query实例的ajax应用之二级联动的后台是采用php来做的
jQuery实例的ajax应用之二级联动的后台是采用php来做的,前台通过jquery的ajax方式实现二级联动数据库表设计 csj_trade id int(11) auto_increment ...
- cas sso原理
以下转载至https://blog.csdn.net/javaloveiphone/article/details/52439613 从结构上看,CAS包含两个部分:CAS Server 和CAS C ...
- HDU5033 building 单调栈+计算几何
正解:单调栈 解题报告: 哇生气辽QAQ本来打了半天feel good都快调出来了然后说换题了QAQ(所以可能那题的代码会过一阵子再放上来了QAQ 不过还是大爆手速打了一通拿到首杀了嘻嘻 美滋滋辽 然 ...
- PyQt5标准对话框
很全的Qt的标准对话框,包含QInputDialog.QColorDialog.QFontDialog.QMessageBox.QOpenFileDialog... 全部是由官网的C++版本,转换成P ...
- openssl配置
1.update openssl yum update openssl 2.修改openssl配置 vim /etc/ssh/sshd_config RSAAuthentication yesPubk ...
- java 原子类
一.基本类原子操作 AtomicBoolean,AtomicInteger,AtomicLong,AtomicReference<V>对boolean,Integer,long,refer ...
- android 6.0之后动态获取权限
Android 6.0 动态权限申请 1. 概述 Android 6.0 (API 23) 之前应用的权限在安装时全部授予,运行时应用不再需要询问用户.在 Android 6.0 或更高版本对权限 ...
- Java-小技巧-002-String 转 long
1.转化 long l = Long.parseLong([String]); 相当于 long l = Long.parseLong([String],10); long l = Long.valu ...
- 发现XMind一个超级牛逼的功能
本来想要自己手动建立下文件夹的结构图,一不小心发现了一个大惊喜. 比如想要看一下360Downloads文件夹下的文件结构,可以先创建一个名叫360Downloads的主节点,然后把其文件夹下的文件直 ...
- python3与mysql:创建表、插入数据54
import pymysql db = pymysql.connect(host=',db='jodb1',port=3307,charset='utf8') # #测试连接开发库成功 # db = ...