AC 代码,洛谷 IDE 能过,但是本地不过。
下载了第一组数据测试:

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
const int N=1e5+10;
LL n,m,p,t,inv[N],mul[N],mul2[N];
LL C(LL a,LL b) {
return mul[a]*mul2[a-b]%p*mul2[b]%p;
}
LL lucas(LL a,LL b) {
if(a<p&&b<p) return C(a,b);
return C(a%p,b%p)*lucas(a/p,b/p)%p;
}
signed main() {
scanf("%lld",&t);
for(; t; t--) {
scanf("%lld%lld%lld",&n,&m,&p);
inv[0]=mul[0]=mul2[0]=1;
inv[1]=mul[1]=mul2[1]=1;
for(int i=2; i<p; i++) inv[i]=((-(p/i)*inv[p%i])%p+p)%p;
for(int i=2; i<p; i++) mul[i]=mul[i-1]*i%p;
for(int i=2; i<p; i++) mul2[i]=mul2[i-1]*inv[i]%p;
printf("%lld\n",lucas(n+m,n));
}
return 0;
}
AC link