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=( ...
随机推荐
- DBCP连接池配置(DBCPUtils.java)
配置文件 db_dbcp.properites driverClass=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/db?useSSL= ...
- HDU-1011 Starship Troopers(树形dp)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hihocoder 1284 - 机会渺茫
N有N_cnt个约数,M有M_cnt个约数,那么总共有N_cnt * M_cnt种对应情况. 假设其中有D_cnt个对应结果是相等的,而这D_cnt个数正好是gcd(N,M)的所有约数. 例如: N= ...
- SQL Fundamentals || Single-Row Functions || 字符函数 character functions
SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使 ...
- 《SEO在网页制作中的应用》视频笔记
学习了慕课网<SEO在网页制作中的应用>视频,今天将里面的知识整理一下. 一.SEO介绍 1. 搜索引擎工作原理 搜索引擎现在主流有百度.谷歌.360,他们都有庞大的搜索引擎数据库,每个 ...
- Effective Objective-C 笔记之熟悉OC
1.在一个类的头文件中尽量少引用其他头文件 如果Person.h 引入了EmployeePerson.h,而后续又有其他类如Human.h又引入了Person.h, 那么EmployeePerson. ...
- Time Profiler Instrument分析卡顿
https://www.jianshu.com/p/080108c969e8 启动Time Profile:Xcode ——> Product ——> Profile ——> Tim ...
- 异步通信----WebSocket
什么是WebSocket? WebSocket API是下一代客户端-服务器的异步通信方法.该通信取代了单个的TCP套接字,使用ws或wss协议,可用于任意的客户端和服务器程序.WebSocket目前 ...
- kubernetes网络原理
1.1. 基础原则 每个Pod都拥有一个独立的IP地址,而且假定所有Pod都在一个可以直接连通的.扁平的网络空间中,不管是否运行在同一Node上都可以通过Pod的IP来访问. k8s中Pod的IP是最 ...
- Python3学习之路~2.6 集合操作
集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变成集合,就自动去重了 关系测试,测试两组数据之前的交集.差集.并集等关系 常用操作 >>> list1 = ...