逆元打表

逆元打表模板

long long re[N],inv[N],fac[N];
void init(int n){
    re[0] = inv[1] = fac[0] = 1;
    for(int i = 1;i <= n;++i) fac[i] = fac[i-1] * i % mod;
    for(int i = 2;i <= n;++i) inv[i] = (mod-mod/i)*inv[mod%i] % mod;
    for(int i = 1;i <= n;++i) re[i] = re[i-1] * inv[i] % mod;
}
long long c(int a,int b){
    if(a < 0) return 0;
    return fac[a]*re[b]%mod*re[a-b]%mod;
}
View Code

 

posted on 2018-10-20 09:53  solvit  阅读(417)  评论(0编辑  收藏  举报

导航