QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#268015 | #5. 在线 O(1) 逆元 | David713 | 100 ✓ | 5032ms | 394508kb | C++14 | 358b | 2023-11-27 22:52:08 | 2024-11-05 21:55:39 |
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;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 696ms
memory: 394456kb
Test #2:
score: 20
Accepted
time: 1106ms
memory: 394476kb
Test #3:
score: 30
Accepted
time: 2860ms
memory: 394508kb
Test #4:
score: 20
Accepted
time: 4137ms
memory: 394400kb
Test #5:
score: 20
Accepted
time: 5032ms
memory: 394496kb