QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#798244 | #5. 在线 O(1) 逆元 | zzafanti | 60 | 3070ms | 394476kb | C++23 | 630b | 2024-12-04 10:09:51 | 2024-12-04 10:09:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using E=long long;
const int Lim=1e8;
int Inv[Lim+1];
const E mod=998244353;
const __int128 brt=((__int128)1<<64)/mod;
void init(int p){
Inv[1]=1;
for(int i=2; i<=Lim; i++){
Inv[i]=(mod-mod/i)*Inv[mod%i]%mod;
}
}
int inv(int x){
if(x<=Lim) return Inv[x];
E now=1;
while(x>Lim){
E t=mod/x;
now=now*(mod-t);
now=now-mod*((brt*now)>>64);
if(now>=mod) now-=mod;
x=mod-x*t;
}
return now*Inv[x]%mod;
}
#ifdef zzafanti
int main(){
init(mod);
cout<<inv(23214153)<<endl;
return 0;
}
#endif // zzafanti
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 798ms
memory: 394476kb
Test #2:
score: 20
Accepted
time: 1295ms
memory: 394472kb
Test #3:
score: 30
Accepted
time: 3070ms
memory: 394428kb
Test #4:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded