AcWing 886. 求组合数 II
原题链接
简单
作者:
wangyj
,
2020-10-24 15:14:56
,
所有人可见
,
阅读 1237
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int fa[100005],af[100005];
int mi(int a,int k,int p)
{
int ans=1;
while(k){
if(k&1)ans=(long long)ans*a%p;
a=(long long)a*a%p;
k>>=1;
}
return ans;
}
int main()
{
int n,a,b,i;
fa[0]=af[0]=1;
for(i=1;i<100005;i++)fa[i]=(long long)fa[i-1]*i%mod,af[i]=(long long)af[i-1]*mi(i,mod-2,mod)%mod;
scanf("%d",&n);
while(n--){
scanf("%d%d",&a,&b);
printf("%lld\n",(long long)fa[a]*af[b]%mod*af[a-b]%mod);
}
return 0;
}