组合数预处理(高效)

这是君玉学长的博客里写的一小段:

https://www.cnblogs.com/lemon-jade/p/8909462.html

const int N=2e6+20;
ll inv(ll b){   return b==1||b==0?1:(mod-mod/b)*inv(mod%b)%mod; }
ll f[N];
ll C(ll n,ll m){
    return f[n]*inv(f[m])%mod*inv(f[n-m])%mod;
}
void init(){
    f[0]=1;
    for(int i=1;i<=N;i++)
        f[i]=f[i-1]*i%mod;
}

另一位学长写的:

https://www.cnblogs.com/sciorz/p/8904234.html

ll mod = 1000000007;
const int maxn = 1000010;
ll qpow(ll a,ll x){
    ll ret=1;
    while (x){
        if (x&1)
            ret = ret*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return ret;
}
ll fac[maxn],inv[maxn];
 
ll init(){
    fac[0]=1;
    for (int i=1;i=0;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
    return 0;
}
 
ll c(ll n,ll m){
    if (n

你可能感兴趣的:(技巧型算法类)