The number of board seeking common combination

 1 LL C[3010][3010];
 2 
 3 void init() {
 4     C[0][0] = 1;
 5     for(int i = 1; i < 3010; i++) {
 6         C[i][0] = 1;
 7         for(int j = 1; j <= i; j++) {
 8             C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
 9         }
10     }
11 }

 

Fermat's Little Theorem plus rapid power demand to optimize the number of combinations

 

LL da[MAXN];//G++ long long
void init()
{
    int i;
    da[0]=1;
    da[1]=1;
    for(i=2;i<MAXN;i++)
        da[i]=i*da[i-1]%MOD;
}
LL quickmod(LL a,LL b)
{
    LL ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%MOD;
            b--;
        }
        b/=2;
        a=((a%MOD)*(a%MOD))%MOD;
    }
    return ans;
}
LL C(LL a, LL b)
{
    return (da[a]%MOD)*(quickmod(da[b]*da[a-b]%MOD,MOD-2))%MOD;
}

 

Number of conventional combination formula:

 

Guess you like

Origin www.cnblogs.com/-Ackerman/p/12169073.html