QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#435118 | #8761. 另一个计数问题 | Wavelet# | AC ✓ | 770ms | 37036kb | C++17 | 2.5kb | 2024-06-08 18:59:39 | 2024-06-08 18:59:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define fir first
#define sec second
#define mpr make_pair
#define vv vector
#define eb emplace_back
#define Fr(i, l, r) for (ll i = l; i <= r; ++i)
#define Rf(i, r, l) for (ll i = r; i >= l; --i)
template<typename T> void Min(T& x, T y) {
if (y < x) x = y;
}
template<typename T> void Max(T& x, T y) {
if (y > x) x = y;
}
const int N = 1000010;
const long long MD = 998244353, inv2 = (MD + 1) / 2;
ll n, sqrt_n;
ll p[N];
bitset<N> npr;
ll mindiv[N];
ll G[N];
int id1[N], id2[N];
ll sum1(ll n) {
// n %= MD;
return ((__int128)n * (n + 1) / 2 - 1) % MD;
}
ll sum2(ll n) {
// n %= MD;
return ((__int128)n * (n + 1) * (n * 2 + 1) / 6 - 1) % MD;
}
void sieve() {
ll lmt = sqrt_n + 100;
Fr (i, 2, lmt) {
if (!npr[i]) p[++p[0]] = i, mindiv[i] = i;
Fr (j, 1, p[0]) {
if (i * p[j] > lmt) break;
npr[i * p[j]] = true;
mindiv[i * p[j]] = p[j];
if (i % p[j] == 0) break;
}
}
p[0] = 1;
}
void calc() {
sqrt_n = floor(sqrt(n)), sieve();
vv<ll> val(1, 0);
for (ll l = 1, v, r; l <= n; l = r + 1) {
v = n / l, r = n / v, val.eb(v);
}
int cnt = (int)val.size() - 1;
Fr (i, 1, cnt) {
G[i] = sum1(val[i]);
if (val[i] > sqrt_n) id2[n / val[i]] = i;
else id1[val[i]] = i;
}
ll sum = 0;
Fr (i, 1, sqrt_n) {
if (p[i] * p[i] > n) break;
for (ll j = 1; j <= cnt && p[i] * p[i] <= val[j]; ++j) {
ll tmp = val[j] / p[i];
ll k = tmp > sqrt_n ? id2[n / tmp] : id1[tmp];
G[j] = ((G[j] - (G[k] - sum) * p[i]) % MD + MD) % MD;
}
sum += p[i];
}
}
void calc2() {
vv<ll> val(1, 0);
for (ll l = 1, v, r; l <= n; l = r + 1) {
v = n / l, r = n / v, val.eb(v);
}
int cnt = (int)val.size() - 1;
Fr (i, 1, cnt) {
G[i] = sum2(val[i]);
if (val[i] > sqrt_n) id2[n / val[i]] = i;
else id1[val[i]] = i;
}
ll sum = 0;
Fr (i, 1, sqrt_n) {
if (p[i] * p[i] > n) break;
for (ll j = 1; j <= cnt && p[i] * p[i] <= val[j]; ++j) {
ll tmp = val[j] / p[i];
ll k = tmp > sqrt_n ? id2[n / tmp] : id1[tmp];
G[j] = ((G[j] - (G[k] - sum) * p[i] % MD * p[i]) % MD + MD) % MD;
}
sum = (sum + p[i] * p[i]) % MD;
}
}
int main() {
cin >> n;
calc();
ll sum = (G[1] - G[2]) % MD;
ll ans = (sum1(n) - sum) % MD;
ans = (ans * ans) % MD;
calc2();
ll s2 = (G[1] - G[2]) % MD;
ans = (ans + s2 - sum2(n)) % MD;
ans = ans * inv2 % MD;
ans = (ans + MD) % MD;
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9992kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9972kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9836kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9792kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9916kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9824kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 1ms
memory: 9976kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 1ms
memory: 9792kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 1ms
memory: 9908kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 1ms
memory: 9988kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 1ms
memory: 9836kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 1ms
memory: 9736kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 1ms
memory: 9824kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 1ms
memory: 9904kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 1ms
memory: 9788kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 9976kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 0ms
memory: 9708kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 0ms
memory: 10060kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 0ms
memory: 10008kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 1ms
memory: 9852kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 0ms
memory: 9856kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 1ms
memory: 10004kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 1ms
memory: 9756kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 1ms
memory: 10020kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 10004kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 1ms
memory: 9868kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 1ms
memory: 9876kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 28ms
memory: 12584kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 32ms
memory: 12708kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 32ms
memory: 14776kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 28ms
memory: 10676kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 28ms
memory: 10552kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 32ms
memory: 10536kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 28ms
memory: 10616kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 55ms
memory: 13528kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 75ms
memory: 15672kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 167ms
memory: 15580kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 211ms
memory: 16128kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 334ms
memory: 23536kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 351ms
memory: 21352kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 380ms
memory: 27552kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 402ms
memory: 22632kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 667ms
memory: 30500kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 752ms
memory: 35820kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 761ms
memory: 37036kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 758ms
memory: 34460kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 770ms
memory: 34340kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 758ms
memory: 35408kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 758ms
memory: 34048kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 767ms
memory: 36028kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"