QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136494 | #5. 在线 O(1) 逆元 | zhouhuanyi | 100 ✓ | 5210ms | 394352kb | C++14 | 465b | 2023-08-08 21:18:03 | 2024-11-05 21:51:30 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define mod 998244353
#define N 100000000
using namespace std;
int MD2(int x)
{
return x<0?x+mod:x;
}
int T,invs[N+1];
void init(int p)
{
invs[1]=1;
for (int i=2;i<=N;++i) invs[i]=MD2(-1ll*(mod/i)*invs[mod%i]%mod);
return;
}
int inv(int x)
{
int a,b;
if (x<=N) return invs[x];
else
{
a=mod/x,b=mod%x;
if ((b<<1)<=x) return 1ll*MD2(-a)*inv(b)%mod;
else return 1ll*(a+1)*inv(x-b)%mod;
}
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 882ms
memory: 394352kb
Test #2:
score: 20
Accepted
time: 1307ms
memory: 394312kb
Test #3:
score: 30
Accepted
time: 3006ms
memory: 394312kb
Test #4:
score: 20
Accepted
time: 4289ms
memory: 394352kb
Test #5:
score: 20
Accepted
time: 5210ms
memory: 394316kb