【模板】线性求逆元

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 3e6+10;
int n;
LL p, inv[N];

int main() {
	scanf("%d%lld", &n, &p);
	inv[1] = 1;
	printf("1\n");
	for (int i = 2; i <= n; i++) 
	{
		inv[i] = (p - p / (LL)i) * inv[p % i] % p;
		printf("%lld\n", inv[i]);
	}
	return 0;
}
posted on 2024-11-29 15:14  Ueesugi_sakura  阅读(9)  评论(0)    收藏  举报