'commit'
This commit is contained in:
23
TangDou/AcWing/NumberTheory/逆元/P3811【模板】乘法逆元.cpp
Normal file
23
TangDou/AcWing/NumberTheory/逆元/P3811【模板】乘法逆元.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user