组合数模板

ll fac[N], inv_fac[N];
ll q_pow(ll a, ll b, ll mod) {
   ll ret = 1;
   for (ll x = a; b; b >>= 1, (x*=x)%=mod){if (b&1)(ret *= x)%=mod;}
   return ret;
}
ll inv(ll x){return q_pow(x, mod-2, mod);}
void init() {
   fac[0] = 1;
   inv_fac[0] = 1;
   for (int i = 1; i < N; i ++) {
      fac[i] = (fac[i-1] * 1ll*i)%mod;
      inv_fac[i] = inv(fac[i]);
   }
}
ll C(ll n, ll m) {return fac[n]*inv_fac[m]%mod * inv_fac[n-m]%mod;}
posted @ 2021-08-12 08:36  u_yan  阅读(43)  评论(0编辑  收藏  举报