当前位置:网站首页>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
边栏推荐
- Redis-01.初识Redis
- 求组合数 AcWing 889. 满足条件的01序列
- 高斯消元 AcWing 884. 高斯消元解异或线性方程组
- [rust notes] 14 set (Part 2)
- There are three kinds of SQL connections: internal connection, external connection and cross connection
- MPLS experiment
- 1.14 - assembly line
- SQLMAP使用教程(一)
- FFmpeg build下载(包含old version)
- [learning] database: several cases of index failure
猜你喜欢
ollvm编译出现的问题纪录
LeetCode-54
Real time clock (RTC)
背包问题 AcWing 9. 分组背包问题
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
Leetcode-6108: decrypt messages
Groupbykey() and reducebykey() and combinebykey() in spark
4. Object mapping Mapster
博弈论 AcWing 893. 集合-Nim游戏
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
随机推荐
Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
Doing SQL performance optimization is really eye-catching
Modnet matting model reproduction
[wustctf2020] plain_ WP
[rust notes] 17 concurrent (Part 1)
11-gorm-v2-03-basic query
1.13 - RISC/CISC
11-gorm-v2-02-create data
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
背包问题 AcWing 9. 分组背包问题
Traversal of leetcode tree
Open source storage is so popular, why do we insist on self-development?
LeetCode 0107. Sequence traversal of binary tree II - another method
Is it impossible for lamda to wake up?
Shutter web hardware keyboard monitoring
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
3.Oracle-控制文件的管理
Leetcode heap correlation
MySQL advanced part 2: SQL optimization
Applicable to Net free barcode API [off] - free barcode API for NET [closed]