当前位置:网站首页>Find the combination number acwing 887. find the combination number III
Find the combination number acwing 887. find the combination number III
2022-07-27 11:18:00 【T_ Y_ F666】
Find the combination number AcWing 887. Find the combination number III
Original link
AcWing 887. Find the combination number III
Algorithm tags
Combinatorial mathematics Combination count Lucas Theorem Inverse element Fast power Fermat's small Theorem
Ideas

Code
#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 The loop only executes b Time , So it's from a Start riding b Number , namely a*(a-1)*…*(a-b+1), That's equal to 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));
}
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- Instructions for mock platform
- 4 search insertion location
- Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
- 求组合数 AcWing 887. 求组合数 III
- An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
- Wilderness search --- search iterations
- Yiwen counts NFT projects valued at more than US $100million
- [shader realizes shake random shaking effect _shader effect Chapter 10]
- Internal and external troubles of digital collection NFT "boring ape" bayc
- 解决 ImportError: cannot import name 'abs' 导入tensorflow报错
猜你喜欢

SQL Server2000数据库错误

pyquery 的使用

IMG SRC is empty or SRC does not exist, and the picture has a white border

The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd

Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen

博弈论 AcWing 893. 集合-Nim游戏

求组合数 AcWing 885. 求组合数 I

Kangaroo cloud stack based on CBO in spark SQL optimization

Use of parsel

How to build a data index system is the most effective. From 0 to 1, we will take you a quick start - 02 live review
随机推荐
What is the mystery of the gate of the meta universe?
properties文件
Kepserver configuration
How to build a real-time development platform to deeply release the value of enterprise real-time data?
Longest ascending subsequence model acwing 1010. Interceptor missile
SQL Server2000数据库错误
最长上升子序列模型 AcWing 1016. 最大上升子序列和
Memory search acwing 901. Skiing
数字三角形模型 AcWing 1015. 摘花生
记忆化搜索 AcWing 901. 滑雪
最长上升子序列模型 AcWing 1012. 友好城市
49 letter ectopic grouping and 242 effective letter ectopic words
XXX packages are looking for funding run 'NPM fund' for details solutions
Neural network learning notes
求组合数 AcWing 888. 求组合数 IV
KEPServer配置
Backpack model acwing 1022. Collection of pet elves
Wechat push - template message parameter configuration
最长上升子序列模型 AcWing 1014. 登山
区间问题 AcWing 906. 区间分组