QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733333 | #9515. 无限地狱 | JWRuixi | 100 ✓ | 2101ms | 47680kb | C++20 | 3.6kb | 2024-11-10 18:19:34 | 2024-11-10 18:19:35 |
Judging History
answer
#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define me(f, x) memset(f, x, sizeof(f))
#define mc(f, g) memcpy(f, g, sizeof(f))
#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 FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
using vi = vector<int>;
#endif
constexpr int P = 998244353;
IL void qm (int &x) {
x += x >> 31 & P;
}
IL void pls (int &x, const LL &y) {
x = (x + y) % P;
}
constexpr int SQ = 1 << 18;
template<int base>
struct gsm {
int a[SQ + 3], b[SQ + 3];
gsm () {
a[0] = b[0] = 1;
L (i, 1, SQ) {
a[i] = (LL)base * a[i - 1] % P;
}
L (i, 1, SQ) {
b[i] = (LL)a[SQ] * b[i - 1] % P;
}
}
int operator () (LL k) const {
return (LL)a[k & (SQ - 1)] * b[k >> 18] % P;
}
};
gsm<2> p2;
constexpr int N = 2e6;
constexpr int M = 1e4;
LL n;
int mu[N + 3], p[N / 10 + 3], cnt;
bool np[N + 3];
int pmu[N + 3], smu[N + 3];
int f[N + 3], fp[N + 3];
int g[N + 3], gp[N + 3];
int h[N + 3], hp[N + 3];
int tot;
LL idx[M + 3];
IL int Mu (LL x) {
return x <= N ? pmu[x] : smu[n / x];
}
IL int W (LL x) {
return x & 1 ? (p2(x / 2) - 1) * 2 % P : (3LL * p2(x / 2 - 1) - 2) % P;
}
IL int F (LL x) {
return x <= N ? f[x] : fp[n / x];
}
IL int G (LL x) {
return x <= N ? g[x] : gp[n / x];
}
IL int H (LL x) {
return x <= N ? h[x] : hp[n / x];
}
void init () {
mu[1] = 1;
L (i, 2, N) {
if (!np[i]) {
p[++cnt] = i;
mu[i] = -1;
}
for (int j = 1; j <= cnt && i * p[j] <= N; ++j) {
np[i * p[j]] = 1;
if (i % p[j] == 0) {
break;
}
mu[i * p[j]] = -mu[i];
}
}
L (i, 1, N) {
pmu[i] = (pmu[i - 1] + P + mu[i]) % P;
}
L (i, 1, N) {
if (i > 1) {
int x = f[i] + p2(i - 2);
L (j, 1, N / i) if (mu[j]) {
pls(g[i * j], (P + 6LL * mu[j]) * x);
pls(h[i * j], (P + 3LL * mu[j]) * x);
}
}
pls(g[i], (P - 2LL) * f[i] + P - p2(i - 1) + 2 * mu[i]);
pls(h[i], (P - 2LL) * f[i] + P - p2(i - 1) + mu[i]);
L (j, 2, N / i) {
pls(f[i * j], h[i] + (p2(j / 2 - 1) - 1LL + P) * g[i]);
}
}
L (i, 2, N) {
qm(f[i] += f[i - 1] - P);
qm(g[i] += g[i - 1] - P);
qm(h[i] += h[i - 1] - P);
}
for (LL l = 1, r; l <= n; l = r + 1) {
r = n / (n / l);
if (n / l <= N) {
break;
}
idx[++tot] = n / l;
}
reverse(idx + 1, idx + tot + 1);
L (i, 1, tot) {
LL x = idx[i];
int k = n / x;
smu[k] = 1;
for (LL l = 2, r; l <= x; l = r + 1) {
r = x / (x / l);
pls(smu[k], (P - Mu(x / l)) * ((r - l + 1) % P));
}
}
L (i, 1, tot) {
LL x = idx[i];
int k = n / x;
for (LL l = 2, r; l <= x; l = r + 1) {
r = x / (x / l);
LL len = (r - l + 1) % P;
pls(fp[k], H(x / l) * len + G(x / l) * (P - len + W(r) + P - W(l - 1)));
}
hp[k] = (fp[k] + p2(x - 1) - 1) % P;
for (LL l = 2, r; l <= x; l = r + 1) {
r = x / (x / l);
int len = Mu(r) - Mu(l - 1);
if (len < 0) {
len += P;
}
pls(hp[k], len * (3LL * F(x / l) + 3LL * p2(x / l - 1) - 2));
}
gp[k] = ((hp[k] + fp[k]) * 2LL + p2(x) - 1) % P;
}
}
int main () {
// FIO("1");
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
init();
cout << (F(n) + p2(n - 1)) % P << '\n';
// cerr << clock() << '\n';
}
// I love WHQ!
詳細信息
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 289ms
memory: 47548kb
input:
6
output:
38
result:
ok 1 number(s): "38"
Test #2:
score: 4
Accepted
time: 294ms
memory: 47244kb
input:
7
output:
73
result:
ok 1 number(s): "73"
Test #3:
score: 4
Accepted
time: 278ms
memory: 47520kb
input:
8
output:
148
result:
ok 1 number(s): "148"
Test #4:
score: 4
Accepted
time: 294ms
memory: 47564kb
input:
9
output:
284
result:
ok 1 number(s): "284"
Test #5:
score: 4
Accepted
time: 287ms
memory: 47252kb
input:
10
output:
565
result:
ok 1 number(s): "565"
Subtask #2:
score: 13
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 13
Accepted
time: 294ms
memory: 47440kb
input:
30
output:
536938322
result:
ok 1 number(s): "536938322"
Test #7:
score: 13
Accepted
time: 297ms
memory: 47244kb
input:
35
output:
210046687
result:
ok 1 number(s): "210046687"
Test #8:
score: 13
Accepted
time: 291ms
memory: 47444kb
input:
38
output:
680532913
result:
ok 1 number(s): "680532913"
Test #9:
score: 13
Accepted
time: 298ms
memory: 47308kb
input:
39
output:
362030079
result:
ok 1 number(s): "362030079"
Test #10:
score: 13
Accepted
time: 293ms
memory: 47324kb
input:
40
output:
723529503
result:
ok 1 number(s): "723529503"
Subtask #3:
score: 17
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 17
Accepted
time: 299ms
memory: 47256kb
input:
2000
output:
686289840
result:
ok 1 number(s): "686289840"
Test #12:
score: 17
Accepted
time: 294ms
memory: 47248kb
input:
2500
output:
672176744
result:
ok 1 number(s): "672176744"
Test #13:
score: 17
Accepted
time: 274ms
memory: 47256kb
input:
2998
output:
77001108
result:
ok 1 number(s): "77001108"
Test #14:
score: 17
Accepted
time: 295ms
memory: 47488kb
input:
2999
output:
337824775
result:
ok 1 number(s): "337824775"
Test #15:
score: 17
Accepted
time: 287ms
memory: 47448kb
input:
3000
output:
636156660
result:
ok 1 number(s): "636156660"
Subtask #4:
score: 21
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 21
Accepted
time: 282ms
memory: 47448kb
input:
100000
output:
809175948
result:
ok 1 number(s): "809175948"
Test #17:
score: 21
Accepted
time: 288ms
memory: 47292kb
input:
200000
output:
425311829
result:
ok 1 number(s): "425311829"
Test #18:
score: 21
Accepted
time: 292ms
memory: 47248kb
input:
500000
output:
302623178
result:
ok 1 number(s): "302623178"
Test #19:
score: 21
Accepted
time: 297ms
memory: 47252kb
input:
900000
output:
683174559
result:
ok 1 number(s): "683174559"
Test #20:
score: 21
Accepted
time: 285ms
memory: 47280kb
input:
1000000
output:
126560600
result:
ok 1 number(s): "126560600"
Subtask #5:
score: 22
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 22
Accepted
time: 306ms
memory: 47372kb
input:
100000000
output:
269652149
result:
ok 1 number(s): "269652149"
Test #22:
score: 22
Accepted
time: 336ms
memory: 47248kb
input:
300000000
output:
421051808
result:
ok 1 number(s): "421051808"
Test #23:
score: 22
Accepted
time: 349ms
memory: 47384kb
input:
700000000
output:
834273337
result:
ok 1 number(s): "834273337"
Test #24:
score: 22
Accepted
time: 387ms
memory: 47272kb
input:
990000000
output:
848544380
result:
ok 1 number(s): "848544380"
Test #25:
score: 22
Accepted
time: 385ms
memory: 47520kb
input:
1000000000
output:
341773916
result:
ok 1 number(s): "341773916"
Subtask #6:
score: 23
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 23
Accepted
time: 1393ms
memory: 47456kb
input:
12000000000
output:
877921487
result:
ok 1 number(s): "877921487"
Test #27:
score: 23
Accepted
time: 1826ms
memory: 47512kb
input:
17000000000
output:
691116504
result:
ok 1 number(s): "691116504"
Test #28:
score: 23
Accepted
time: 2091ms
memory: 47660kb
input:
19900000000
output:
87007717
result:
ok 1 number(s): "87007717"
Test #29:
score: 23
Accepted
time: 2101ms
memory: 47680kb
input:
19990000000
output:
455948458
result:
ok 1 number(s): "455948458"
Test #30:
score: 23
Accepted
time: 2101ms
memory: 47608kb
input:
20000000000
output:
128153394
result:
ok 1 number(s): "128153394"