传送门
貌似就是lucas的板子题啊。
练一练手感觉挺舒服的^_^
代码:
#include<bits/stdc++.h>
#define mod 10007
#define ll long long
using namespace std;
int T_T;
ll n,m,fac[mod+5],ifac[mod+5];
inline ll lucas(ll a,ll b){
if(a<b)return 0;
if(a<mod&&b<mod)return fac[a]*ifac[b]%mod*ifac[a-b]%mod;
return lucas(a%mod,b%mod)*lucas(a/mod,b/mod)%mod;
}
int main(){
scanf("%d",&T_T),fac[0]=1,ifac[1]=ifac[0]=1;
for(ll i=1;i<mod;++i)fac[i]=fac[i-1]*i%mod;
for(ll i=2;i<mod;++i)ifac[i]=(mod-mod/i)*ifac[mod%i]%mod;
for(ll i=2;i<mod;++i)(ifac[i]*=ifac[i-1])%=mod;
while(T_T--)scanf("%lld%lld",&n,&m),printf("%lld\n",lucas(n,m));
return 0;
}