QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667367 | #5. 在线 O(1) 逆元 | liuziao | 100 ✓ | 4855ms | 81968kb | C++23 | 370b | 2024-10-22 22:31:08 | 2024-10-22 22:31:17 |
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;
}
详细
Pretests
Final Tests
Test #1:
score: 30
Accepted
time: 133ms
memory: 81968kb
Test #2:
score: 40
Accepted
time: 575ms
memory: 81800kb
Test #3:
score: 30
Accepted
time: 4855ms
memory: 81920kb