QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#526522 | #5. 在线 O(1) 逆元 | December456 | 100 ✓ | 4417ms | 19504kb | C++14 | 617b | 2024-08-21 17:01:32 | 2024-11-05 22:03:11 |
Judging History
answer
#include "inv.h"
constexpr int INIT_BOUND = 4000000;
constexpr int P = 998244353;
int _inv[INIT_BOUND];
void init(int p) {
_inv[1] = 1;
for (int i = 2; i < INIT_BOUND; i ++) {
_inv[i] = (long long){p - p / i} * _inv[p % i] % p;
}
}
int inv(int x) {
int ret = 1;
while (x >= INIT_BOUND) {
int y = P % x;
if (y << 1 <= x) {
ret = (long long){P - P / x} * ret % P;
x = y;
} else {
ret = (P / x + 1ll) * ret % P;
x = x - y;
}
}
return (long long){ret} * _inv[x] % P;
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 24ms
memory: 19356kb
Test #2:
score: 20
Accepted
time: 455ms
memory: 19320kb
Test #3:
score: 30
Accepted
time: 2155ms
memory: 19456kb
Test #4:
score: 20
Accepted
time: 3442ms
memory: 19308kb
Test #5:
score: 20
Accepted
time: 4417ms
memory: 19504kb