QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641048 | #5. 在线 O(1) 逆元 | SkyMaths | 100 ✓ | 4877ms | 394456kb | C++20 | 546b | 2024-10-14 18:04:29 | 2024-10-14 18:04:34 |
Judging History
answer
#include<bits/stdc++.h>
// #include "inv.h"
#define rep(i,l,r) for (int i(l), i##end(r); i <= i##end; ++i)
#define per(i,r,l) for (int i(r), i##end(l); i >= i##end; --i)
using namespace std;
const int N = 1e8 + 9, Mod = 998244353;
int n = N - 9, MMI[N];
void init(int p) {
MMI[1] = 1;
rep (i, 2, n) MMI[i] = Mod - 1ll * (Mod / i) * MMI[Mod % i] % Mod;
}
int inv(int x) {
if (x <= n) return MMI[x];
int q = Mod / x, r = Mod % x;
if (r < x / 2) return Mod - 1ll * q * inv(r) % Mod;
return 1ll * (q + 1) * inv(x - r) % Mod;
}
Details
Pretests
Final Tests
Test #1:
score: 30
Accepted
time: 643ms
memory: 394456kb
Test #2:
score: 40
Accepted
time: 1044ms
memory: 394316kb
Test #3:
score: 30
Accepted
time: 4877ms
memory: 394328kb