const int MAXN = 1e5 + 10;//MAXN要大于mod
int f[MAXN];
int pow_mod(int a, int n, int mod)//费马小定理,a^(mod-2)%mod(mod是质数)
{
if (n == 0)
return 1;
int x = pow_mod(a, n / 2, mod);
int ans = (long long)x * x % mod;
if (n % 2)
ans = ((long long)ans * a) % mod;
return ans;
}
void Init(int mod) {
f[0] = 1;
for (int i = 1; i <= mod; i++)
f[i] = (ll)f[i - 1] * i%mod;
}
int Comb(int n, int m,int mod) {
if (n < m)
return 0;
return (ll)f[n] * pow_mod((ll)f[m]*f[n-m]%mod , mod - 2,mod)%mod;
}
int Lucas(int n, int m, int mod) {
return m ? (ll)Lucas(n / mod, m / mod, mod) * Comb(n%mod, m%mod, mod) % mod : 1;
}
int Counter_Lucas(int n, int m, int mod) {
Init(mod);
return Lucas(n, m, mod);
}
求Counter_Lucas()函数丢进去,就能求出C(n,m)%mod(mod是质数)