0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 16:36:26 +00:00

P3811 【模板】乘法逆元

https://www.luogu.com.cn/record/91843036
This commit is contained in:
Baoshuo Ren 2022-10-28 09:39:07 +08:00
parent af5bf736f8
commit e93b52517e
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 26 additions and 9 deletions

View File

@ -1,18 +1,29 @@
#include <bits/stdc++.h> #include <iostream>
using namespace std; using std::cin;
using std::cout;
const char endl = '\n';
long long inv[3000005]; const int N = 3e6 + 5;
int n, p, inv[N];
int main() { int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> p;
inv[0] = 0; inv[0] = 0;
inv[1] = 1; inv[1] = 1;
int n, p;
scanf("%d%d", &n, &p); cout << inv[1] << endl;
printf("1\n");
for (int i = 2; i <= n; ++i) { for (int i = 2; i <= n; i++) {
inv[i] = (long long)p - (p / i) * inv[p % i] % p; inv[i] = p - static_cast<long long>(p) / i * inv[p % i] % p;
printf("%d\n", inv[i]);
cout << inv[i] << endl;
} }
return 0; return 0;
} }

BIN
Luogu/P3811/data/P3811_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P3811/data/P3811_3.out (Stored with Git LFS) Normal file

Binary file not shown.