#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=10007;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline ll power(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1) res=res*a%mod; a=a*a%mod; b>>=1;
}
return res;
}
inline ll C(ll n,ll m)
{
ll n0=1,m0=1;
for(ll i=n-m+1;i<=n;i++) n0=n0*i%mod;
for(ll i=1;i<=m;i++) m0=m0*i%mod;
return n0*power(m0,mod-2)%mod;
}
inline ll Lucas(ll n,ll m)
{
if(m==0) return 1;
return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
int main()
{
int t;
t=read();
ll n,m;
while(t--)
{
n=(ll)read();
m=(ll)read();
printf("%lld\n",Lucas(n,m));
}
return 0;
}
一本通1656:Combination
最新推荐文章于 2024-06-01 15:44:18 发布