QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#480316 | #5. 在线 O(1) 逆元 | NOI_AK_ME# | 100 ✓ | 1892ms | 19552kb | C++23 | 859b | 2024-07-16 13:30:04 | 2024-07-16 13:30:04 |
Judging History
answer
#pragma once
#pragma GCC optimize("Ofast, unroll-loops")
#include "inv.h"
unsigned a[3035136], g[974849];
int inv(int x) {
const unsigned p = (unsigned long long) x * g[x >> 10] % 998244353;
return (unsigned long long) g[x >> 10] * (p < 3035136 ? a[p] : 998244353 - a[998244353 - p]) % 998244353;
}
unsigned getinv(unsigned x) {
return x == 1 ? 1 : 974849 - (unsigned long long)(974849 / x) * getinv(974849 % x) % 974849;
}
void init(int) {
for (unsigned i = 987; i; --i) {
unsigned inv = getinv(i);
for (unsigned j = 1; j ^ 988;++j) {
g[(unsigned long long) j * inv % 974849] = i;
g[974849 - (unsigned long long) j * inv % 974849] = 998244353 - i;
}
}
g[0] = a[1] = 1;
#pragma unroll
for (unsigned i = 2; i ^ 3035136;++i)
a[i] = 998244353 - (unsigned long long)(998244353 / i) * a[998244353 % i] % 998244353;
}
详细
Test #1:
score: 30
Accepted
time: 14ms
memory: 19544kb
Test #2:
score: 40
Accepted
time: 201ms
memory: 19552kb
Test #3:
score: 30
Accepted
time: 1892ms
memory: 19552kb