#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inv[4000010], n, p, mod;
void get_inv() {
inv[1] = 1;
cout << inv[1] << endl;
for (int i = 2; i <= n; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
cout << inv[i] << endl;
}
}
int main() {
cin >> n >> p;
mod = p;
get_inv();
return 0;
}
乘法逆元 - OI Wiki (oi-wiki.org)
// C++ Version
s[0] = 1;
for (int i = 1; i <= n; ++i) s[i] = s[i - 1] * a[i] % p;
sv[n] = qpow(s[n], p - 2);
// 当然这里也可以用 exgcd 来求逆元,视个人喜好而定.
for (int i = n; i >= 1; --i) sv[i - 1] = sv[i] * a[i] % p;
for (int i = 1; i <= n; ++i) inv[i] = sv[i] * s[i - 1] % p;