QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#850155#5. 在线 O(1) 逆元mnbvcxz12360 4984ms91696kbC++23496b2025-01-09 20:56:452025-01-09 20:56:45

Judging History

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

  • [2025-01-09 20:56:45]
  • 评测
  • 测评结果:60
  • 用时:4984ms
  • 内存:91696kb
  • [2025-01-09 20:56:45]
  • 提交

answer

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

constexpr int mod=998244353;

ll inver[10000005];
bool vis[10000005];

int xd(int a) {
    if(a<=10000000 and vis[a])return inver[a];
    if(a<=10000000)vis[a]=1;
    if(a<=10000000)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: 16ms
memory: 91688kb

Test #2:

score: 20
Accepted
time: 1212ms
memory: 91636kb

Test #3:

score: 30
Accepted
time: 4984ms
memory: 91696kb

Test #4:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded