QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#298946 | #5. 在线 O(1) 逆元 | Untitled_unrevised | 70 | 1495ms | 490600kb | C++14 | 395b | 2024-01-06 16:06:55 | 2024-01-06 16:06:55 |
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
Test #1:
score: 30
Accepted
time: 31ms
memory: 490576kb
Test #2:
score: 40
Accepted
time: 1495ms
memory: 490600kb
Test #3:
score: 0
Time Limit Exceeded