QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106141 | #5. 在线 O(1) 逆元 | zhoukangyang | 0 | 155ms | 38376kb | C++17 | 1.2kb | 2023-05-16 18:26:43 | 2023-05-16 18:26:46 |
Judging History
answer
#include<bits/stdc++.h>
#include "inv.h"
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
#define eb emplace_back
using namespace std;
const int B = 1024, buf = 3, mod = 998244353, N = 6e6 + 7;
int K, ml[N], iv[N], dis[N];
int Inv(int x) {
return x < N ? iv[x] : (ll) Inv(mod % x) * (mod - mod / x) % mod;
}
int inv(int w) {
int d = w >> 10, M = ml[d];
return !M ? Inv(w) : (ll) iv[w * M - dis[d]] * M % mod;
}
void init(int rp) {
K = mod / B;
L(fb, 1, B * buf) {
int cur = 0, Add = fb * B;
for(int p = 0; p <= K; ) {
if(cur <= K * buf) {
ml[p] = fb;
cur += Add, ++p;
} else {
int A = (mod - cur + Add - 1) / Add;
cur += A * Add, p += A;
}
if(cur >= mod) cur -= mod;
}
}
int count = 0;
L(i, 1, K) if(ml[i]) dis[i] = (ll) ml[i] * i * B / mod * mod, ++count;
// cout << 1. * count / K << endl;
iv[1] = 1;
L(i, 2, N - 1) iv[i] = (ll) iv[mod % i] * (mod - mod / i) % mod;
}
Details
Test #1:
score: 0
Wrong Answer
time: 155ms
memory: 38376kb
Test #2:
score: 0
Wrong Answer
time: 150ms
memory: 36948kb
Test #3:
score: 0
Wrong Answer
time: 151ms
memory: 37916kb