Day 21(twenty-first)-quick power and combinatorial number
重铸华农荣光 我辈义不容辞
Day 21 - quick power and combinatorial number
护花使者太能摇了,听了停不下来
#include<iostream>
using namespace std;
typedef long long ll;
const int N=100010,mod=1e9+7;
int fact[N],infact[N];
int qmi(int a,int k,int p)
{
int ans=1;
while(k)
{
if(k&1) ans=(ll)ans*a%p;
k>>=1;
a=(ll)a*a%p;
}
return ans;
}
int main()
{
fact[0]=infact[0]=1;
for(int i=1;i<N;i++)
{
fact[i]=(ll)fact[i-1]*i%mod;
infact[i]=(ll)infact[i-1]*qmi(i,mod-2,mod)%mod;
}
int t;
cin>>t;
while(t--)
{
int a,b;
cin>>a>>b;
cout<<(ll)fact[a]*infact[b]%mod*infact[a-b]%mod<<"\n";
}
return 0;
}