QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667367 | #5. 在线 O(1) 逆元 | liuziao | 100 ✓ | 5479ms | 82024kb | C++23 | 370b | 2024-10-22 22:31:08 | 2024-11-05 22:06:35 |
Judging History
answer
#include "inv.h"
const int kMaxN = 2e7 + 5;
int mod, iv[kMaxN];
void init(int p) {
iv[1] = 1;
::mod = p;
for (int i = 2; i <= 2e7; ++i) {
iv[i] = 1ll * (mod - mod / i) * iv[mod % i] % mod;
}
}
int inv(int x) {
int coef = 1;
for (; x > 2e7; x = mod % x) coef = 1ll * coef * (mod - mod / x) % mod;
return 1ll * coef * iv[x] % mod;
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 243ms
memory: 81832kb
Test #2:
score: 20
Accepted
time: 762ms
memory: 81828kb
Test #3:
score: 30
Accepted
time: 2892ms
memory: 82024kb
Test #4:
score: 20
Accepted
time: 4508ms
memory: 81836kb
Test #5:
score: 20
Accepted
time: 5479ms
memory: 82024kb