QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#431110 | #8761. 另一个计数问题 | Repeater | AC ✓ | 994ms | 34796kb | C++20 | 2.3kb | 2024-06-04 22:53:46 | 2024-06-04 22:53:46 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using i128 = __int128;
constexpr int p = 998244353;
std::vector<int> vis, primes;
void sieve(i64 n)
{
vis.resize(n + 1);
primes.clear();
primes.emplace_back(0);
for(int i = 2; i <= n; i++)
{
if(!vis[i]) primes.emplace_back(i);
for(auto j : primes)
{
if(j == 0) continue;
if(i * j > n) break;
vis[i * j] = 1;
if(i % j == 0) break;
}
}
}
auto Min_25(i64 n)
{
int sqrt_n = std::sqrt(n) + 1;
sieve(sqrt_n);
int m = primes.size() - 1;
std::vector sum(2, std::vector<i64>(m + 1));
for(int i = 1; i <= m; i++)
{
sum[0][i] = (sum[0][i - 1] + 1LL * primes[i]) % p;
sum[1][i] = (sum[1][i - 1] + 1LL * primes[i] * primes[i] % p) % p;
}
std::vector<i64> val;
std::vector id(2, std::vector<int>(2 * sqrt_n + 1));
std::vector g(2, std::vector<i64>(2 * sqrt_n + 1));
for(i64 l = 1, r; l <= n; l = r + 1)
{
r = n / (n / l);
val.emplace_back(n / l);
int cur = val.size() - 1;
if(n / l <= sqrt_n) id[0][n / l] = cur;
else id[1][l] = cur;
i128 t = (n / l) % p;
g[0][cur] = (t * (t + 1) / 2 % p - 1 + p) % p;
g[1][cur] = (t * (t + 1) * (2 * t + 1) / 6 % p - 1 + p) % p;
}
for(int x = 1; x <= m; x++)
{
i64 i = primes[x];
for(int j = 0; j < val.size() && i * i <= val[j]; j++)
{
i64 t = val[j] / i;
if(t <= sqrt_n) t = id[0][t];
else t = id[1][n / t];
g[0][j] = (g[0][j] - 1LL * i * (g[0][t] - sum[0][x - 1] + p) % p + p) % p;
g[1][j] = (g[1][j] - 1LL * i * i % p * (g[1][t] - sum[1][x - 1] + p) % p + p) % p;
}
}
return std::make_pair(g[0][id[1][1]], g[1][id[1][1]]);
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n; std::cin >> n;
auto S1 = [&](i64 n) -> i64
{
return i64(i128(n) * (n + 1) / 2 % p);
};
auto S2 = [&](i64 n) -> i64
{
return i64(i128(n) * (n + 1) * (2 * n + 1) / 6 % p);
};
auto [s1, s2] = Min_25(n);
auto [s11, s22] = Min_25(n / 2);
s1 = (s1 - s11 + p) % p, s2 = (s2 - s22 + p) % p;
i64 ans = ((S1(n) * S1(n) - S2(n) + p) % p * (p + 1) / 2 % p - S1(n) + 1 + p) % p;
ans = (ans - 1LL * s1 * (S1(n) - s1 - 1 + p) % p - (1LL * s1 * s1 - s2 + p) % p * (p + 1) / 2 % p + p + p) % p;
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3872kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 40ms
memory: 5916kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 40ms
memory: 5808kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 40ms
memory: 5700kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 32ms
memory: 5828kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 36ms
memory: 5696kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 40ms
memory: 5912kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 36ms
memory: 5820kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 64ms
memory: 7592kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 88ms
memory: 8364kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 218ms
memory: 12452kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 272ms
memory: 14132kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 428ms
memory: 19592kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 445ms
memory: 19692kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 485ms
memory: 20404kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 499ms
memory: 21140kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 875ms
memory: 31656kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 945ms
memory: 34436kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 980ms
memory: 33388kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 979ms
memory: 34296kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 994ms
memory: 33280kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 983ms
memory: 34796kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 991ms
memory: 33036kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 993ms
memory: 33564kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"