QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293468 | #5. 在线 O(1) 逆元 | iee | 100 ✓ | 5487ms | 394540kb | C++11 | 439b | 2023-12-29 10:43:25 | 2024-11-05 21:57:23 |
Judging History
answer
#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "inv.h"
using namespace std;
constexpr int N = 1e8;
int v[N], P;
void init(int p) {
P = p;
v[1] = 1;
for (int i = 2; i < N; i++) {
v[i] = P - 1ll * v[P % i] * (P / i) % P;
}
}
int inv(int x) {
int res = 1;
while (x >= N) {
res = P - 1ll * res * (P / x) % P;
x = P % x;
}
return 1ll * res * v[x] % P;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 683ms
memory: 394540kb
Test #2:
score: 20
Accepted
time: 1102ms
memory: 394380kb
Test #3:
score: 30
Accepted
time: 2773ms
memory: 394524kb
Test #4:
score: 20
Accepted
time: 4186ms
memory: 394536kb
Test #5:
score: 20
Accepted
time: 5487ms
memory: 394324kb