OI初学者的代码求调
查看原帖
OI初学者的代码求调
448884
快乐的大童楼主2022/2/8 18:35

RT,输出全是0.

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int R(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}return x*f;
}
inline void write(int x){
	if(x<0){putchar('-');x=-x;}
	char z[20];int y=0;
	while(x||!y){z[y++]=x%10+48;x/=10;}
	while(y--) putchar(z[y]);putchar(10); 
}
const int N=1e5+5;
int t,n,m,p;
int fact[N];
int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(res*x)%p;
		x=(x*x)%p;
		y>>=1;
	}
	return res;
}
int C(int x,int y){
	if(y>x) return 0;
	else return (fact[x]*(ksm(fact[y],p-2)%p)*(ksm(fact[x-y],p-2)%p))%p;
}
int lucas(int x,int y){
	if(!y) return 1;
	else return C(x%p,y%p)*lucas(x/p,y/p)%p;
}
signed main(){
	t=R();
	while(t--){
		n=R(),m=R(),p=R();
		fact[0]=1;
		for(int i=1;i<=n;i++){
			fact[i]=(fact[i-1]*i)%p;
		} 
		write(lucas(n+m,n));
	}
}
2022/2/8 18:35
加载中...