当前位置:网站首页>Find the combination number acwing 887 Find combination number III
Find the combination number acwing 887 Find combination number III
2022-07-05 06:23: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
边栏推荐
- Winter vacation water test 1 Summary
- 1.手动创建Oracle数据库
- 【LeetCode】Day95-有效的数独&矩阵置零
- Leetcode-3: Longest substring without repeated characters
- MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
- How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
- 博弈论 AcWing 894. 拆分-Nim游戏
- Leetcode-6108: decrypt messages
- MySQL advanced part 2: the use of indexes
- 4. Object mapping Mapster
猜你喜欢
博弈论 AcWing 894. 拆分-Nim游戏
MySQL advanced part 2: optimizing SQL steps
Real time clock (RTC)
Single chip computer engineering experience - layered idea
栈 AcWing 3302. 表达式求值
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
2021apmcm post game Summary - edge detection
4.Oracle-重做日志文件管理
SQLMAP使用教程(一)
Bit of MySQL_ OR、BIT_ Count function
随机推荐
Client use of Argo CD installation
TCP's understanding of three handshakes and four waves
Filter the numbers and pick out even numbers from several numbers
LeetCode-61
Leetcode divide and conquer / dichotomy
论文阅读报告
Modnet matting model reproduction
[wustctf2020] plain_ WP
Applicable to Net free barcode API [off] - free barcode API for NET [closed]
MySQL advanced part 2: optimizing SQL steps
AE tutorial - path growth animation
Open source storage is so popular, why do we insist on self-development?
[leetcode] day95 effective Sudoku & matrix zeroing
Liunx starts redis
[rust notes] 13 iterator (Part 2)
11-gorm-v2-02-create data
MySQL advanced part 1: triggers
栈 AcWing 3302. 表达式求值
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
求组合数 AcWing 889. 满足条件的01序列