QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#489190 | #5. 在线 O(1) 逆元 | qwef_ | 70 | 1566ms | 515504kb | C++23 | 563b | 2024-07-24 18:52:03 | 2024-07-24 18:52:03 |
Judging History
answer
//#include <bits/stdc++.h>
#include "inv.h"
typedef long long ll;
const int N=1.31e8+114,p=998244353;
int a[N];
inline void add(int& a,int b){a=(a+b>=p?a+b-p:a+b);}
void init(int _){
a[1]=1;
for(int i=2;i<N;++i) a[i]=(ll)(p-p/i)*a[p%i]%p;
}
int inv(int x){
for(int i=1,j=x;;++i,add(j,x))
if(j<N){
int k=0,o=a[j];
do{
if(i&1) add(k,o);
o=(o>=499122177?o+o-p:o+o);
}while(i>>=1);
return k;
}
}
//int main(){
// init(998244353);
// int x;
// std::cin >> x;
// std::cout << query(x) << std::endl;
// return 0;
//}
Details
Pretests
Final Tests
Test #1:
score: 30
Accepted
time: 809ms
memory: 515404kb
Test #2:
score: 40
Accepted
time: 1566ms
memory: 515504kb
Test #3:
score: 0
Time Limit Exceeded