组合数模板
void c()
{
for(int i=0;i<MAX;i++)
{
C[i][0]=1;
for(int j=1;j<=i;j++)
C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
}
update:
另一个模板:
const int MAXN=2e5+5; LL n,m,a[MAXN]; int NY[MAXN]; LL pow_mod(LL a, LL b) { a %= mod; LL ret = 1LL; while(b){ if(b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } LL inv(LL a) { return pow_mod(a, mod-2); } LL F[MAXN], Finv[MAXN];//F是阶乘,Finv是逆元的阶乘 void init(){ F[0] = Finv[0] = 1LL; for(int i = 1; i < MAXN; i ++){ F[i] = F[i-1] * 1LL * (LL)i % mod; Finv[i] = Finv[i-1] * 1LL * inv(i) % mod; } } LL C(LL n, LL m){//comb(n, m)就是C(n, m) if(m < 0 || m > n) return 0; return F[n] * 1LL * Finv[n - m] % mod * Finv[m] % mod; }
再加一个模板:
ll pow_mod(ll a,ll b) { a%=mod; ll res=1; while(b) { if(b&1)res=res*a%mod; a=a*a%mod; b>>=1; } return res; } ll inv(ll a) { return pow_mod(a,mod-2); } ll c(ll a,ll b) { if(b==0) return 0; if(a==b) return 1; ll up=1,down=1; for(int i=1;i<=a;i++) up=up*i%mod; for(int i=1;i<=b;i++) down=down*i%mod; for(int i=1;i<=a-b;i++) down=down*i%mod; return up*inv(down)%mod; }