【模板】乘法逆元
#include <cstdio> #include <cmath> #include <cstring> #include <iostream> #include <algorithm> using namespace std; long long n, p, ans[3000010]; int main() { scanf("%lld%lld", &n, &p); ans[1] = 1; for (int i = 2; i <= n; i++) ans[i] = 1LL * (p - p / i) * ans[p % i] % p; for (int i = 1; i <= n; i++) printf("%lld\n", ans[i]); return 0; }