QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136495 | #5. 在线 O(1) 逆元 | yyyyxh | 100 ✓ | 4920ms | 82004kb | C++17 | 430b | 2023-08-08 21:21:44 | 2024-11-05 21:51:30 |
Judging History
answer
#include <cstdio>
#include <cassert>
#pragma GCC optimize(2,3,"Ofast")
using namespace std;
const int P=998244353,N=20000003;
typedef long long ll;
int a[N];
void init(int _P){
assert(_P==P);
a[1]=1;
for(int i=2;i<N;++i) a[i]=(ll)a[P%i]*(P-P/i)%P;
}
int inv(int x){
int res=1;
while(x>=N){
int t=P%x;
if(x-t<t) res=(ll)res*(P/x+1)%P,x-=t;
else res=(ll)res*(P-P/x)%P,x=t;
}
return (ll)res*a[x]%P;
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 152ms
memory: 82004kb
Test #2:
score: 20
Accepted
time: 616ms
memory: 82004kb
Test #3:
score: 30
Accepted
time: 2471ms
memory: 81896kb
Test #4:
score: 20
Accepted
time: 3936ms
memory: 82000kb
Test #5:
score: 20
Accepted
time: 4920ms
memory: 82000kb