当前位置:网站首页>求组合数 AcWing 887. 求组合数 III
求组合数 AcWing 887. 求组合数 III
2022-07-27 10:35:00 【T_Y_F666】
求组合数 AcWing 887. 求组合数 III
原题链接
算法标签
组合数学 组合计数 Lucas定理 逆元 快速幂 费马小定理
思路

代码
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 105;
double a[N][N], eps = 1e-8;
int n;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
int qmi(int a, int b, int p){
int ans=1;
while(b){
if(b&1){
ans=ans*a%p;
}
a=a*a%p;
b>>=1;
}
return ans;
}
int C(int a, int b, int p){
if(a<b){
return 0;
}else{
int res=1;
// for循环只执行了b次,所以是从a开始乘了b个数,即a*(a-1)*…*(a-b+1),也就等于a!/(a-b)!
for(int i=1, j=a; i<=b; ++i, --j){
res=res*j%p;
res=res*qmi(i, p-2, p)%p;
}
return res;
}
}
int lu(int a, int b, int p){
if(a<p&&b<p){
return C(a, b, p);
}else{
return C(a%p, b%p, p)*lu(a/p, b/p, p)%p;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
n=read();
while(n--){
int a=read(), b=read(), p=read();
printf("%lld\n", lu(a, b, p));
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
- 背包模型 AcWing 1024. 装箱问题
- 01 BTC cryptology principle
- 如何组装一个注册中心
- 背包问题 AcWing 9. 分组背包问题
- Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
- 最长上升子序列模型 AcWing 272. 最长公共上升子序列
- Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
- 6 find the smallest letter larger than the target letter
- Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
猜你喜欢

Internal and external troubles of digital collection NFT "boring ape" bayc

Longest ascending subsequence model acwing 1014. mountaineering

Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!

解决 ImportError: cannot import name 'abs' 导入tensorflow报错

Instructions for mock platform

Longest ascending subsequence model acwing 482. Chorus formation
![Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.](/img/7f/f42f9267cdff35522c260ef073bab9.png)
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.

Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?

中国剩余定理 AcWing 204. 表达整数的奇怪方式

JVM judges that the object is dead, and practices verify GC recycling
随机推荐
10 complete half of the questions
洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
properties文件
6 find the smallest letter larger than the target letter
如何组装一个注册中心
熵与形态的非递进现象
Use of parsel
SQL Server2000 database error
最长上升子序列模型 AcWing 1016. 最大上升子序列和
JVM judges that the object is dead, and practices verify GC recycling
迭代次数和熵之间关系的一个验证试验
The difference of iteration number and information entropy
Ten year structure five year life-07 young and vigorous transformation
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.
迭代次数的差异与信息熵
Integrated design of communication perception based on CSI: problems, challenges and Prospects
Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
Instructions for mock platform
最长上升子序列模型 AcWing 1014. 登山
14 check whether integers and their multiples exist