标签:main show 分享 hid div using img inline har
1 #include<bits/stdc++.h> 2 #define N 100010 3 using namespace std; 4 typedef long long ll; 5 ll a[N]; 6 int p; 7 ll pow(ll y,int z,int p){ 8 y%=p;ll ans=1; 9 for(int i=z;i;i>>=1,y=y*y%p)if(i&1)ans=ans*y%p; 10 return ans; 11 } 12 ll C(ll n,ll m){ 13 if(m>n)return 0; 14 return ((a[n]*pow(a[m],p-2,p))%p*pow(a[n-m],p-2,p)%p); 15 } 16 ll Lucas(ll n,ll m){ 17 if(!m)return 1; 18 return C(n%p,m%p)*Lucas(n/p,m/p)%p; 19 } 20 inline int read(){ 21 int f=1,x=0;char ch; 22 do{ch=getchar();if(ch==‘-‘)f=-1;}while(ch<‘0‘||ch>‘9‘); 23 do{x=x*10+ch-‘0‘;ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘); 24 return f*x; 25 } 26 int main(){ 27 int T=read(); 28 while(T--){ 29 int n=read(),m=read();p=read(); 30 a[0]=1; 31 for(int i=1;i<=p;i++)a[i]=(a[i-1]*i)%p; 32 cout<<Lucas(n+m,n)<<endl; 33 } 34 }
标签:main show 分享 hid div using img inline har
原文地址:http://www.cnblogs.com/TheRoadToAu/p/7794375.html