QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671517#5. 在线 O(1) 逆元QSteve_Paul0 0ms0kbC++23692b2024-10-24 13:05:322024-11-05 22:06:53

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 22:06:53]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-24 13:05:33]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-24 13:05:32]
  • 提交

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 <= 1e7; i++)
        fac[i] = fac[i] * i % P;
    invfac[(int)1e7] = inv(fac[(int)1e7]);
    for (i64 i = 1e7 - 1; i >= 0; i--)
        invfac[i] = invfac[i + 1] * (i + 1) % P;
}

int inv(int x)
{
    return invfac[x] * fac[x - 1] % P;
}

Details


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