IN
10
4025 19326 9973
7700 12101 9973
13621 29372 9973
8990 362 9973
10440 10101 9973
18517 22970 9973
14871 22433 9973
26273 15511 9973
30325 1620 9973
19469 32344 9973
OUT
0
3202
0
104
8995
0
6261
0
9893
0
我的代码:
#include<bits/stdc++.h>
using namespace std;
int T,n,m,p,jc[2000005],jcn[2000005];
int ksm(int a,int x)
{
int re=1;
while(x>0)
{
if(x%2==1)re=(1ll*re*a)%p;
a=(1ll*a*a)%p;
x/=2;
}
return re;
}
void st()
{
jc[0]=jc[1]=1;
jcn[0]=jcn[1]=1;
for(int i=2;i<=p;i++)
{
jc[i]=(1ll*jc[i-1]*i)%p;
jcn[i]=ksm(jc[i],p-2);
}
}
int c(int n,int m)
{
return (1ll*(1ll*jc[m]*jcn[m-n])%p)*jcn[n]%p;
}
int qc(int n,int m)
{
int re=1;
re=1ll*re*c(n%p,m%p)%p;
if(n/p>0&&m/p>0)re=1ll*re*qc(n/p,m/p)%p;
return re;
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--)
{
cin>>n>>m>>p;
st();
cout<<qc(n,m+n)<<"\n";
}
}