QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#705362#5. 在线 O(1) 逆元lvliang0 0ms0kbC++14737b2024-11-02 23:08:532024-11-05 22:07:53

Judging History

This is the latest submission verdict.

  • [2024-11-05 22:07:53]
  • 管理员手动重测本题所有提交记录
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2024-11-02 23:08:56]
  • Judged
  • Verdict: 0
  • Time: 676ms
  • Memory: 393824kb
  • [2024-11-02 23:08:53]
  • Submitted

answer

// inv.cpp
#include "inv.h"
#include <vector>
#include <iostream>

// 由于 p 是固定的,我们可以直接在这里初始化
const int MOD = 998244353;
const int N = 1e8 + 10;

// 预先计算的逆元表,用于优化计算
std::vector<int> invTable(N);

void init(int p) {
    // 由于题目保证 p=998244353,我们可以在这里直接使用这个值
    // 如果 p 不是固定的,可以在这里计算每个数的逆元并存储
    invTable[1] = 1;
    for (int i = 2; i < N; ++i) {
        // 计算 i 的逆元,即 i^(MOD-2) % MOD
        invTable[i] = invTable[MOD % i] * (MOD - MOD / i) % MOD;
    }
}

int inv(int x) {
    // 直接返回预先计算的逆元
    return invTable[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