标签:time -- long vector space cst using pre ++
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<ctime>
#include<queue>
#include<vector>
using namespace std;
const int N=100005;
int n,m,p;
long long A[N+5],B[N+5];
int C(int n,int m,int p){
if(m>n){
return 0;
}
return A[n]*B[n-m]%p*B[m]%p;
}
int Lucas(int n, int m, int p){
if(!m){
return 1;
}
return C(n%p, m%p, p)*Lucas(n/p, m/p, p)%p;
}
int main(){
int t;
scanf("%d", &t);
while(t--){
scanf("%d%d%d",&n,&m,&p);
A[0]=B[0]=A[1]=B[1]=1;
n+=m;
for(int i=2;i<=p;i++){
B[i]=-(p/i)*B[p%i]%p;
}
for(int i=2;i<=p;i++){
A[i]=A[i-1]*i%p,
B[i]=B[i-1]*B[i]%p;
}
printf("%d\n",(Lucas(n,m,p)+p)%p);
}
return 0;
}
标签:time -- long vector space cst using pre ++
原文地址:https://www.cnblogs.com/ukcxrtjr/p/11707001.html