线性求逆元

https://leetcode.com/problems/count-the-number-of-good-subsequences/description/

求[1,n]的所有数逆元在模p下的逆元, 用pow(n,p – 2,p)太慢了。所有用下面代码

inv[1] = 1;
for (int i = 2; i <= n; ++i) {
  inv[i] = (long long)(p - p / i) * inv[p % i] % p;
}