组合数取模(Lucas定理)
模数为p=9901
#include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<iostream> #define ll long long using namespace std; int m,n,p=9901; ll modfac[10000]={1,1};//1-n的阶乘取模后结果 ll fp(ll a,ll b){ if(b==1) return a; ll i=fp(a,b/2); if(b%2==0) return i*i%p; else return i*i*a%p; } ll c(ll n,ll m) { if(m>n) return 0; return (modfac[n]*fp(modfac[n-m],p-2)*fp(modfac[m],p-2))%p; } ll lucas(ll a,ll b){ if(b==0) return 1; else return c(a%p,b%p)*lucas(a/p,b/p)%p; } int main() { scanf("%d%d",&n,&m); for(int i=2;i<=min(9905,n);i++){ modfac[i]=modfac[i-1]*i%p; } printf("%lld",lucas(n,m)); return 0; }