1.exgcd
LL Inv(LL a, LL p) 
{
    LL x, y, d;
    d = extgcd(a, p, x, y)
    if(d == 1) return (x%p+p)%p;
    return -1;
}
2.费马小定理
A*A^(p-2)=1(modp)
3.线性递推 
Inv[1]=1;
For(int i=2;i<MAX;i++)inv[i]=(p-p/i)*inv[p%i]%p;
4.阶乘逆元
  inv[0]=inv[1]=inv_fac[0]=fac[0]=1;
  rep(i,2,maxn) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
  rep(i,1,maxn) fac[i]=fac[i-1]*i%mod;
  rep(i,1,maxn) inv_fac[i]=inv_fac[i-1]*inv[i]%mod;