QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606190 | #5. 在线 O(1) 逆元 | Yoshinow2001 | 100 ✓ | 2498ms | 17184kb | C++23 | 564b | 2024-10-02 23:00:25 | 2024-11-05 22:04:21 |
Judging History
answer
#include<bits/stdc++.h>
#include "inv.h"
const int N=(1<<21)+5;
const int mod=998244353;
const int B=1024;
int pl[N],iv[N];
void init(int p){
const int n=2*B*B;
iv[1]=1;
for(int i=2;i<=n;i++) iv[i]=1ll*(mod-iv[mod%i])*(mod/i)%mod;
for(int i=1;i<=B;i++){
int x=0;
while(x<=B*B){
long long w=1ll*x*B*i%mod;
if(w<=B*B||w>=mod-B*B) pl[x]=i,x++;
else x+=(mod-B*B-w+B*i-1)/(B*i);
}
}
}
int inv(int x){
long long w=1ll*x*pl[x>>10]%mod;
if(w<=2*B*B) return 1ll*iv[w]*pl[x/B]%mod;
else return 1ll*(mod-iv[mod-w])*pl[x/B]%mod;
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 18ms
memory: 16704kb
Test #2:
score: 20
Accepted
time: 273ms
memory: 17184kb
Test #3:
score: 30
Accepted
time: 1259ms
memory: 16676kb
Test #4:
score: 20
Accepted
time: 1990ms
memory: 16196kb
Test #5:
score: 20
Accepted
time: 2498ms
memory: 16780kb