QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#798241 | #5. 在线 O(1) 逆元 | zzafanti | 80 | 5874ms | 238276kb | C++23 | 570b | 2024-12-04 10:03:45 | 2024-12-04 10:03:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using E=long long;
const int Lim=3e7;
E 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 t=mod/x;
E now=(mod-t)*inv(mod-x*t);
now=now-mod*((brt*now)>>64);
if(now>=mod) now-=mod;
return now;
}
#ifdef zzafanti
int main(){
init(mod);
cout<<inv(23214153)<<endl;
return 0;
}
#endif // zzafanti
详细
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 431ms
memory: 238276kb
Test #2:
score: 20
Accepted
time: 1128ms
memory: 238096kb
Test #3:
score: 30
Accepted
time: 3840ms
memory: 238236kb
Test #4:
score: 20
Accepted
time: 5874ms
memory: 238104kb
Test #5:
score: 0
Time Limit Exceeded