You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
534 B

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3000010;
//递推打表求逆元
LL inv[N];
void getInv(LL n, LL p) {
inv[1] = 1;
for (int i = 2; i <= n; i++)
inv[i] = inv[p % i] * (p - p / i) % p;
}
int main() {
LL n, p;
cin >> n >> p;
getInv(n, p);
for (int i = 1; i <= n; i++) printf("%d\n", inv[i]); //可以AC
// cout << inv[i] << "\n"; //可以AC
// cout << inv[i] << endl; //这里使用cout就会TLE两个点!
return 0;
}