链接
题解
( n m ) = n ( n − 1 ) ( n − 2 ) … ( n − m + 1 ) m ! \binom{n}{m} = \frac{n(n-1)(n-2)\dots(n-m+1)}{m!} (mn)=m!n(n−1)(n−2)…(n−m+1)
代码
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
ll n, m, mod, inv[maxn];
int main()
{
ll T=read(), i;
while(T--)
{
n=read(), m=read(), mod=read();
ll ans=1;
inv[1]=1;rep(i,2,m)inv[i]=inv[mod%i]*(mod-mod/i)%mod;
rep(i,1,m)(ans=ans*(n-i+1)%mod*inv[i])%=mod;
printf("%lld\n",ans);
}
return 0;
}