const long long mod=1000000007;
const int maxn=100000;
typedef long long LL;
LL fac[maxn+9],inv_fac[maxn];
LL quickpow(LL x,LL n)
{
LL res=1;
x=x%mod;
while(n)
{
if(n%2==1)res=(res*x)%mod;
n=n/2;
x=(x*x)%mod;
}
return res;
}
void print()
{
fac[0]=1;
for(int i=1;i<=maxn;i++)
fac[i]=(fac[i-1]*i)%mod;//阶乘取余打表
//切记,求阶乘逆元时maxn最大值为mod-1,因为用这个公式时要保证待求逆元的数(此处为n!)要和mod互质。
inv_fac[maxn]=quickpow(fac[maxn],mod-2);//最大阶乘逆元
for(int i=maxn-1;i>=0;i--)
inv_fac[i]=(inv_fac[i+1]*(i+1))%mod;//递推阶乘逆元
}
阶乘取余打表,阶乘逆元打表
最新推荐文章于 2019-01-09 14:14:00 发布