QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#435108 | #8761. 另一个计数问题 | Wavelet# | WA | 1ms | 12096kb | C++17 | 3.0kb | 2024-06-08 18:55:36 | 2024-06-08 18:55:37 |
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 f[N];
ll sum1(ll n) {
return (n * (n + 1) / 2 - 1) % MD;
}
ll sum2(ll n) {
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;
ll t1 = G[1];
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];
f[i] = (t1 - G[1] + p[i] + MD) % MD;
}
}
void calc2() {
// 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] = 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;
// ll t1 = G[1];
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;
// f[i] = (t1 - G[1] + p[i] + MD) % MD;
}
}
int main() {
cin >> n;
calc();
// ll ans = (1ll - sum2(n)) % MD;
// ans += (sum1(n) - 1) * (sum1(n) - 1);
// ans %= MD;
// ll sum = (G[1] - G[2]) % MD;
// ans += sum * sum;
// ans %= MD;
// ans -= sum * (sum1(n) - 1) * 2;
// ans %= MD;
// ans = (ans + MD) % MD;
// ans = ans * inv2 % MD;
// cout << ans << '\n';
// ll ans = (sum1(n) * sum1(n) - sum2(n)) % MD * inv2 % MD;
ll sum = (G[1] - G[2]) % MD;
ll ans = (sum1(n) - sum) % MD;
ans = (ans * ans) % MD;
// ans = (ans - sum * sum1(n)) % MD;
calc2();
ll s2 = (G[1] - G[2]) % MD;
// ans = (ans + s2) % MD;
ans = (ans + s2 - sum2(n)) % MD;
ans = ans * inv2 % MD;
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 11764kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 1ms
memory: 11756kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11876kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 1ms
memory: 11868kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 1ms
memory: 11876kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 1ms
memory: 11952kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 1ms
memory: 11880kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 0ms
memory: 11760kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 0ms
memory: 11880kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 1ms
memory: 12044kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 0ms
memory: 11876kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 1ms
memory: 11936kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 1ms
memory: 12024kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 1ms
memory: 12092kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 1ms
memory: 11828kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 12096kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 0ms
memory: 12016kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 1ms
memory: 11888kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 1ms
memory: 11892kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: -100
Wrong Answer
time: 1ms
memory: 11888kb
input:
220895
output:
-123632271
result:
wrong answer 1st numbers differ - expected: '874612082', found: '-123632271'