适用于mod为素数 o(N)
void init() { int i; pp[0] = 1; for(i = 1; i <= N-10 ; i++) { pp[i] = (pp[i-1]*i)%mod; } } LL fastmod(LL a,LL k) { LL b = 1; while(k) { if(k&1) b = a*b%mod; a = (a%mod)*(a%mod)%mod; k/=2; } return b; } LL calc(int n,int m) { return (pp[n]*fastmod((pp[m]*pp[n-m])%mod,mod-2))%mod)%mod; }
时间: 2025-01-05 14:37:23