QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#699519 | #9515. 无限地狱 | A_programmer | 100 ✓ | 1764ms | 74148kb | C++17 | 2.8kb | 2024-11-02 09:33:06 | 2024-11-02 09:33:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int B = 1.5e6;
const int X = (2e10 / B);
ll F1[B + 5], F2[262150], pre[B + 5], N;
ll fpow(ll x) { return F2[x >> 18] * F1[x & 262143] % mod; }
int mu[B + 5], pr[500005], prc;
bool v[B + 5];
void precalc()
{
F1[0] = F2[0] = 1;
for (int i = 1; i <= B; i++) F1[i] = F1[i - 1] * 2 % mod;
for (int i = 1; i <= (1 << 18); i++) F2[i] = F2[i - 1] * F1[1 << 18] % mod;
v[1] = 1; mu[1] = 1;
for (int i = 2; i <= B; i++)
{
if (!v[i]) pr[++prc] = i, mu[i] = -1;
for (int j = 1; j <= prc && pr[j] <= B / i; j++)
{
v[i * pr[j]] = 1; mu[i * pr[j]] = mu[i] ? mod - mu[i] : 0;
if (i % pr[j] == 0) { mu[i * pr[j]] = 0; break; }
}
}
for (int i = 1; i <= B; i++)
{
pre[i] = pre[i - 1] + mu[i];
if (pre[i] >= mod) pre[i] -= mod;
}
}
ll f[B + 5], g[B + 5], h[B + 5];
void Solve()
{
for (int d = 1; d <= B; d++)
{
(h[d] += f[d] + (d == 1 ? 0 : F1[d - 2])) %= mod;
g[d] = (h[d] * 2 + f[d] * 2 + F1[d - 1]) % mod;
for (int n = d << 1, j = 2; n <= B; n += d, j++)
{
(f[n] += h[d] + (F1[j / 2 - 1] - 1) * g[d]) %= mod;
(h[n] += mu[j] * (f[d] * 3 + (d == 1 ? 1 : F1[d - 2] * 3))) %= mod;
}
}
for (int i = 2; i <= B; i++) (f[i] += f[i - 1]) %= mod, (g[i] += g[i - 1]) %= mod, (h[i] += h[i - 1]) %= mod;
}
ll F[X + 10], G[X + 10], H[X + 10], S[X + 10];
inline ll qF(ll x) { return x <= B ? f[x] : F[N / x]; }
inline ll qG(ll x) { return x <= B ? g[x] : G[N / x]; }
inline ll qH(ll x) { return x <= B ? h[x] : H[N / x]; }
inline ll qS(ll x) { return x <= B ? pre[x] : S[N / x]; }
inline ll qP(ll x) { return (x & 1) ? (fpow(x / 2) - 1) * 2 % mod : (3 * fpow(x / 2 - 1) - 2) % mod; }
int main()
{
int start = clock();
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N; precalc(); Solve();
if (N <= B) return cout << (fpow(N - 1) + f[N]) % mod, 0;
for (int i = (N / B); i; i--)
{
ll n = N / i, l = 2, r, len, d;
S[i] = 1;
while (l <= n)
{
r = n / (d = n / l), len = (r - l + 1) % mod;
(F[i] += len * qH(d) + qG(d) * (qP(r) + 2 * mod - qP(l - 1) - len)) %= mod;
(S[i] += (mod - len) * qS(d)) %= mod;
l = r + 1;
}
l = 2; H[i] = (F[i] + fpow(n - 1) - 1) % mod;
while (l <= n)
{
r = n / (d = n / l), len = qS(r) - qS(l - 1);
if (len < 0) len += mod;
(H[i] += len * (3 * qF(d) + 3 * fpow(d - 1) - 2)) %= mod;
l = r + 1;
}
G[i] = (H[i] * 2 + F[i] * 2 + fpow(n) - 1) % mod;
}
cout << (fpow(N - 1) + F[1]) % mod;
return 0;
}
详细
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 167ms
memory: 73788kb
input:
6
output:
38
result:
ok 1 number(s): "38"
Test #2:
score: 4
Accepted
time: 170ms
memory: 73652kb
input:
7
output:
73
result:
ok 1 number(s): "73"
Test #3:
score: 4
Accepted
time: 173ms
memory: 72620kb
input:
8
output:
148
result:
ok 1 number(s): "148"
Test #4:
score: 4
Accepted
time: 176ms
memory: 73736kb
input:
9
output:
284
result:
ok 1 number(s): "284"
Test #5:
score: 4
Accepted
time: 165ms
memory: 72180kb
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: 174ms
memory: 73040kb
input:
30
output:
536938322
result:
ok 1 number(s): "536938322"
Test #7:
score: 13
Accepted
time: 175ms
memory: 73740kb
input:
35
output:
210046687
result:
ok 1 number(s): "210046687"
Test #8:
score: 13
Accepted
time: 166ms
memory: 72620kb
input:
38
output:
680532913
result:
ok 1 number(s): "680532913"
Test #9:
score: 13
Accepted
time: 175ms
memory: 72832kb
input:
39
output:
362030079
result:
ok 1 number(s): "362030079"
Test #10:
score: 13
Accepted
time: 172ms
memory: 72892kb
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: 171ms
memory: 73592kb
input:
2000
output:
686289840
result:
ok 1 number(s): "686289840"
Test #12:
score: 17
Accepted
time: 187ms
memory: 72820kb
input:
2500
output:
672176744
result:
ok 1 number(s): "672176744"
Test #13:
score: 17
Accepted
time: 168ms
memory: 72316kb
input:
2998
output:
77001108
result:
ok 1 number(s): "77001108"
Test #14:
score: 17
Accepted
time: 171ms
memory: 72364kb
input:
2999
output:
337824775
result:
ok 1 number(s): "337824775"
Test #15:
score: 17
Accepted
time: 173ms
memory: 72708kb
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: 176ms
memory: 72844kb
input:
100000
output:
809175948
result:
ok 1 number(s): "809175948"
Test #17:
score: 21
Accepted
time: 163ms
memory: 73596kb
input:
200000
output:
425311829
result:
ok 1 number(s): "425311829"
Test #18:
score: 21
Accepted
time: 168ms
memory: 72788kb
input:
500000
output:
302623178
result:
ok 1 number(s): "302623178"
Test #19:
score: 21
Accepted
time: 173ms
memory: 72276kb
input:
900000
output:
683174559
result:
ok 1 number(s): "683174559"
Test #20:
score: 21
Accepted
time: 168ms
memory: 73732kb
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: 185ms
memory: 73248kb
input:
100000000
output:
269652149
result:
ok 1 number(s): "269652149"
Test #22:
score: 22
Accepted
time: 193ms
memory: 73432kb
input:
300000000
output:
421051808
result:
ok 1 number(s): "421051808"
Test #23:
score: 22
Accepted
time: 224ms
memory: 73092kb
input:
700000000
output:
834273337
result:
ok 1 number(s): "834273337"
Test #24:
score: 22
Accepted
time: 238ms
memory: 73408kb
input:
990000000
output:
848544380
result:
ok 1 number(s): "848544380"
Test #25:
score: 22
Accepted
time: 252ms
memory: 73700kb
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: 1108ms
memory: 73608kb
input:
12000000000
output:
877921487
result:
ok 1 number(s): "877921487"
Test #27:
score: 23
Accepted
time: 1519ms
memory: 74032kb
input:
17000000000
output:
691116504
result:
ok 1 number(s): "691116504"
Test #28:
score: 23
Accepted
time: 1736ms
memory: 72496kb
input:
19900000000
output:
87007717
result:
ok 1 number(s): "87007717"
Test #29:
score: 23
Accepted
time: 1759ms
memory: 74012kb
input:
19990000000
output:
455948458
result:
ok 1 number(s): "455948458"
Test #30:
score: 23
Accepted
time: 1764ms
memory: 74148kb
input:
20000000000
output:
128153394
result:
ok 1 number(s): "128153394"