另类求组合数
ll C[220][220]; void getC(){ memset(C,0,sizeof(C)); for(int i = 0; i < 220; 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; } } }
上面这种过时了,复杂度高。
下面这种快很多。
ll pow_mod(ll x, ll n){ ll res=1; while(n>0){ if(n&1)res=res*x%mod; x=x*x%mod; n>>=1; } return res; } ll C(int a, int b) {
if(a < 0 || b < 0 || a < b) return 0; return fac[a] * inv[b] % mod * inv[a-b] % mod; } fac[0] = 1;for(int i = 1; i <= mx; i ++) fac[i] = fac[i-1] * i %mod; inv[mx] = pow_mod(fac[mx], mod-2); for(int i = mx-1; i >= 0; i --) inv[i] = inv[i+1] *(i+1) % mod;
费马小定理:
const ll mod = 1e9+7; const ll md = 1e9+6; c[0][0] = 1; for (int i = 1; i <= 1000; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) { c[i][j] = (c[i-1][j-1] + c[i-1][j]) % md; } }