组合数取模(待补充)

来源:互联网 发布:手感好的键盘 知乎 编辑:程序博客网 时间:2024/06/12 01:11
const ll M=1e5+3;ll fac[100005];            //阶乘ll inv_of_fac[100005];        //阶乘的逆元ll qpow(ll x,ll n){    ll ret=1;    for(; n; n>>=1)    {        if(n&1) ret=ret*x%mod;        x=x*x%mod;    }    return ret;}void init(){    fac[1]=1;    for(int i=2; i<=M; i++)        fac[i]=fac[i-1]*i%mod;    inv_of_fac[M]=qpow(fac[M],mod-2);    for(int i=M-1; i>=0; i--)        inv_of_fac[i]=inv_of_fac[i+1]*(i+1)%mod;}ll C(ll a,ll b){    if(b>a) return 0;    if(b==0) return 1;    return fac[a]*inv_of_fac[b]%mod*inv_of_fac[a-b]%mod;}
0 0
原创粉丝点击