QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650587 | #5. 在线 O(1) 逆元 | yduck | 100 ✓ | 5150ms | 394496kb | C++14 | 358b | 2024-10-18 15:41:56 | 2024-10-18 15:41:57 |
Judging History
answer
#include "inv.h"
const int N = 1e8;
int mod;
int inv_list[N + 7];
void init(int p){
mod = p;
inv_list[0] = inv_list[1] = 1;
for (register int i = 2; i <= N; i++){
inv_list[i] = mod - 1ll * (mod / i) * inv_list[mod % i] % mod;
}
}
int inv(int x){
if (x <= N) return inv_list[x];
return mod - 1ll * (mod / x) * inv(mod % x) % mod;
}
Details
Pretests
Final Tests
Test #1:
score: 30
Accepted
time: 666ms
memory: 394368kb
Test #2:
score: 40
Accepted
time: 1136ms
memory: 394484kb
Test #3:
score: 30
Accepted
time: 5150ms
memory: 394496kb