标签:for printf define getc code quick oid n+2 quic
Code:
#include <cstdio>
#define ll long long
const int N=100000;
ll p,fac[N+20];
ll quick_pow(ll d,ll k)
{
ll f=1;
while(k)
{
if(k&1) f=f*d%p;
d=d*d%p;
k>>=1;
}
return f;
}
void init(ll k)
{
fac[0]=fac[1]=1;
for(ll i=2;i<=k;i++)
fac[i]=fac[i-1]*i%p;
}
ll getC(ll n,ll m)
{
return n>m?0:fac[m]*quick_pow(fac[m-n],p-2)%p*quick_pow(fac[n],p-2)%p;
}
ll lucas(ll n,ll m)
{
return getC(n%p,m%p)*(n/p?lucas(n/p,m/p):1)%p;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll n,m;
scanf("%lld%lld%lld",&n,&m,&p);
init(m+n);
printf("%lld\n",lucas(m,m+n));
}
return 0;
}
2018.7.10
标签:for printf define getc code quick oid n+2 quic
原文地址:https://www.cnblogs.com/ppprseter/p/9290931.html