XDU 1032
#include<cstdio> typedef long long ll; const ll mod=10007; ll feima(ll a,ll b) { ll c=1; while(b) { if(b&1) c=c*a%mod; a=a*a%mod; b=b>>1; } return c; } ll C(ll a,ll b) { if(a<b) return 0; if(a==b) return 1; if(b>a-b) b=a-b; ll ca=1,cb=1; for(ll i=0;i<b;i++) { ca=ca*(a-i)%mod; cb=cb*(b-i)%mod; } return ca*feima(cb,mod-2)%mod; } /*LL Lucas(LL n,LL m) { if(m==0) return 1; return C(n%p,m%p)*Lucas(n/p,m/p)%p; }*/ ll Lucas(ll n,ll m) { ll ans=1; while(n&&m&&ans) { ans=ans%mod*C(n%mod,m%mod)%mod; n/=mod; m/=mod; } return ans; } int main() { ll n,m; while(~scanf("%lld%lld",&n,&m)) printf("%lld\n",Lucas(m,n)); return 0; }