QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188495 | #5. 在线 O(1) 逆元 | EnofTaiPeople | 100 ✓ | 5769ms | 394432kb | C++14 | 510b | 2023-09-25 21:28:23 | 2023-09-25 21:28:24 |
Judging History
answer
#include<bits/stdc++.h>
#include "inv.h"
using namespace std;
using ll=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]=ll(M-M/x)*nv[M%x]%M;
}
int sol(int d){
if(d<N)return nv[d];
if(d<M-d){
return ll(M-M/d)*sol(M%d)%M;
}else{
d=M-d;
return ll(M/d)*sol(M%d)%M;
}
}
int inv(int x){
ll res=1;
while(x>=N){
x<M-x?res=-res:x=M-x;
res=res*(M/x)%M,x=M%x;
}res=res*nv[x]%M;
return res<0?res+M:res;
}
Details
Test #1:
score: 30
Accepted
time: 724ms
memory: 394404kb
Test #2:
score: 40
Accepted
time: 1288ms
memory: 394216kb
Test #3:
score: 30
Accepted
time: 5769ms
memory: 394432kb