QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188498 | #5. 在线 O(1) 逆元 | EnofTaiPeople | 100 ✓ | 5074ms | 394448kb | C++14 | 367b | 2023-09-25 21:29:43 | 2024-11-05 21:52:45 |
Judging History
answer
#include<bits/stdc++.h>
#include "inv.h"
using namespace std;
using ul=unsigned long long;
const int N=1e8+8,M=998244353;
int nv[N];
void init(int p){
int x;
nv[0]=nv[1]=1;
for(x=2;x<N;++x)
nv[x]=ul(M-M/x)*nv[M%x]%M;
}
int inv(int x){
ul res=1;
while(x>=N){
x<M-x?res=M-res:x=M-x;
res=res*(M/x)%M,x=M%x;
}res=res*nv[x]%M;
return res;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 684ms
memory: 394448kb
Test #2:
score: 20
Accepted
time: 1112ms
memory: 394328kb
Test #3:
score: 30
Accepted
time: 2850ms
memory: 394328kb
Test #4:
score: 20
Accepted
time: 4150ms
memory: 394332kb
Test #5:
score: 20
Accepted
time: 5074ms
memory: 394332kb