QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#640878 | #5. 在线 O(1) 逆元 | masterhuang | 100 ✓ | 5170ms | 42952kb | C++20 | 347b | 2024-10-14 16:40:05 | 2024-11-05 22:05:44 |
Judging History
answer
#include "inv.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+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;
}
详细
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 52ms
memory: 42740kb
Test #2:
score: 20
Accepted
time: 558ms
memory: 42752kb
Test #3:
score: 30
Accepted
time: 2596ms
memory: 42844kb
Test #4:
score: 20
Accepted
time: 4420ms
memory: 42764kb
Test #5:
score: 20
Accepted
time: 5170ms
memory: 42952kb