QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188498 | #5. 在线 O(1) 逆元 | EnofTaiPeople | 100 ✓ | 5578ms | 394412kb | C++14 | 367b | 2023-09-25 21:29:43 | 2023-09-25 21:29:44 |
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;
}
Details
Test #1:
score: 30
Accepted
time: 685ms
memory: 394412kb
Test #2:
score: 40
Accepted
time: 1191ms
memory: 394284kb
Test #3:
score: 30
Accepted
time: 5578ms
memory: 394176kb