QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#298946 | #5. 在线 O(1) 逆元 | Untitled_unrevised | 60 | 5044ms | 490772kb | C++14 | 395b | 2024-01-06 16:06:55 | 2024-11-05 21:57:27 |
Judging History
answer
#include <vector>
#include "inv.h"
std::vector<int> invmem;
unsigned long long s;
int P;
void init(int p) {
s = ((p - 1) >> 3) + 1;
invmem = std::vector<int>(s);
P = p;
invmem[1] = 1;
}
int inv(int x) {
if(x >= s) return P - (unsigned long long) (P / x) * inv(P % x) % P;
return invmem[x] ? invmem[x] : (invmem[x] = P - (unsigned long long) (P / x) * inv(P % x) % P);
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 24ms
memory: 490744kb
Test #2:
score: 20
Accepted
time: 1262ms
memory: 490764kb
Test #3:
score: 30
Accepted
time: 5044ms
memory: 490772kb
Test #4:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded