QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606190 | #5. 在线 O(1) 逆元 | Yoshinow2001 | 100 ✓ | 2747ms | 17588kb | C++23 | 564b | 2024-10-02 23:00:25 | 2024-10-02 23:00:27 |
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;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 30
Accepted
time: 19ms
memory: 16760kb
Test #2:
score: 40
Accepted
time: 308ms
memory: 16292kb
Test #3:
score: 30
Accepted
time: 2747ms
memory: 17588kb