QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#850094#5. 在线 O(1) 逆元mnbvcxz12360 4258ms12668kbC++23491b2025-01-09 20:20:182025-01-09 20:20:19

Judging History

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

  • [2025-01-09 20:20:19]
  • 评测
  • 测评结果:60
  • 用时:4258ms
  • 内存:12668kb
  • [2025-01-09 20:20:18]
  • 提交

answer

#include"inv.h"
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

constexpr int mod=998244353;

ll inver[1000005];
bool vis[1000005];

int xd(int a) {
    if(a<=1000000 and vis[a])return inver[a];
    if(a<=1000000)vis[a]=1;
    if(a<=1000000)return a <= 1 ? a : inver[a]=mod - (long long)(mod/a) * xd(mod % a) % mod;
    return mod - (long long)(mod/a) * xd(mod % a) % mod;
}


void init(int p){
    inver[1]=1;
}

int inv(int x){
    return xd(x);
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 13ms
memory: 12668kb

Test #2:

score: 20
Accepted
time: 871ms
memory: 12480kb

Test #3:

score: 30
Accepted
time: 4258ms
memory: 12668kb

Test #4:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded