QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640896 | #5. 在线 O(1) 逆元 | masterhuang | 100 ✓ | 4341ms | 20164kb | C++20 | 349b | 2024-10-14 16:45:54 | 2024-10-14 16:45:55 |
Judging History
answer
#include "inv.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1<<22|5,mod=998244353;
int n=N-5,I[N];
void init(int p)
{
I[1]=1;
for(int i=2;i<=n;i++) I[i]=mod-1ll*(mod/i)*I[mod%i]%mod;
}
int inv(int x)
{
if(x<=n) return I[x];int q=mod/x,r=mod%x;
if(r<x/2) return mod-1ll*q*inv(r)%mod;
return 1ll*(q+1)*inv(x-r)%mod;
}
Details
Pretests
Final Tests
Test #1:
score: 30
Accepted
time: 24ms
memory: 20000kb
Test #2:
score: 40
Accepted
time: 451ms
memory: 20164kb
Test #3:
score: 30
Accepted
time: 4341ms
memory: 20084kb