标签:== one mod open oid for col adb closed
组合数取mod
条件mod是质数,inv 是逆元,fac是阶层;
用于n在10^5左右
maxn=100505;
ll fact[maxn],inv[maxn]; ll Pow(ll x,ll n){ ll ans=1,base=x; while(n){ if(n&1) ans=ans*base%mod; base=base*base%mod; n>>=1; } return ans; } void init(){ fact[0]=1; for (int i = 1; i < maxn; ++i) { fact[i]=fact[i-1]*i%mod; } inv[maxn-1]=Pow(fact[maxn-1],mod-2); for (int i = maxn-2; i >= 0; --i) { inv[i]=inv[i+1]*(i+1)%mod; } } ll C(ll n, ll m) { if(n==m||m==0) return 1; if(m>n) return 0; return ((long long)fact[n]*inv[m]%mod)*inv[n-m]%mod; }
标签:== one mod open oid for col adb closed
原文地址:https://www.cnblogs.com/Lamboofhome/p/11722732.html