QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671515 | #5. 在线 O(1) 逆元 | QSteve_Paul | 0 | 0ms | 0kb | C++23 | 692b | 2024-10-24 13:04:54 | 2024-11-05 22:06:53 |
Judging History
answer
#include "inv.h"
using i64 = long long;
constexpr int MAXN = 1e7 + 5;
constexpr int P = 998244353;
i64 qpow(i64 a, i64 n)
{
i64 ans = 1;
while (n)
{
if(n & 1)
ans = ans * a % P;
a = a * a % P;
n >>= 1;
}
return ans;
}
i64 inv(i64 a)
{
return qpow(a, P - 2);
}
int fac[MAXN];
int invfac[MAXN];
void init(int p)
{
fac[0] = 1;
for (i64 i = 1; i <= 1e8; i++)
fac[i] = fac[i] * i % P;
invfac[(int)1e8] = inv(fac[(int)1e8]);
for (i64 i = 1e8 - 1; i >= 0; i--)
invfac[i] = invfac[i + 1] * (i + 1) % P;
}
int inv(int x)
{
return invfac[x] * fac[x - 1] % P;
}
详细
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