QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#241458 | #5. 在线 O(1) 逆元 | mfeitveer | 0 | 0ms | 0kb | C++14 | 731b | 2023-11-06 07:59:10 | 2024-11-05 21:54:26 |
Judging History
answer
#include "inv.h"
const int M = 133834517;
const int mod = 998244353;
typedef long long ll;
struct HashMap
{
int ct, a[M], v[M], nxt[M], head[M];
inline int &operator[](const int &tmp)
{
int x = 19260817ll * tmp % mod;
for(int i = head[x];i;i = nxt[i])
if(a[i] == tmp) return v[i];
nxt[++ct] = head[x], head[x] = ct;
a[ct] = tmp; return v[ct];
}
inline bool find(int tmp)
{
int x = 19260817ll * tmp % mod;
for(int i = head[x];i;i = nxt[i])
if(a[i] == tmp) return 1;
return 0;
}
} mp;
ll ask(ll x)
{
if(mp.find(x)) return mp[x];
return mp[x] = (mod - mod / x) * ask(mod % x) % mod;
}
void init(int p)
{
mp[1] = 1;
}
int inv(int x)
{
return ask(x);
}
Details
Pretests
Final Tests
Test #1:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
Test #3:
score: 0
Runtime Error
Test #4:
score: 0
Runtime Error
Test #5:
score: 0
Runtime Error