QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#705445 | #5. 在线 O(1) 逆元 | lvliang | 0 | 0ms | 0kb | C++14 | 560b | 2024-11-02 23:30:25 | 2024-11-05 22:07:59 |
Judging History
answer
#include "inv.h"
#include <vector>
#include <iostream>
const int N = 1e7 + 10;
std::vector<int> vec(N);
int quickPow(int base, int power, int mod) {
int result = 1;
base = base % mod;
while (power > 0) {
if (power & 1) {
result = (result * base) % mod;
}
base = (base * base) % mod;
power >>= 1;
}
return result;
}
void init(int p) {
vec[1] = 1;
for (int i = 2; i < N; i++) {
vec[i] = quickPow(i, p - 2, p);
}
}
int inv(int x) {
return vec[x];
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
Test #3:
score: 0
Runtime Error
Test #4:
score: 0
Runtime Error
Test #5:
score: 0
Runtime Error