QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#465998 | #8761. 另一个计数问题 | koala | WA | 83ms | 74248kb | C++14 | 4.0kb | 2024-07-07 14:39:48 | 2024-07-07 14:39:49 |
Judging History
answer
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
using namespace std;
const int N = 1e6 + 9, MOD = 998244353;
typedef long long ll;
ll read() {
ll x = 0, s = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
s = -1;
for (; isdigit(ch); ch = getchar())
x = x * 10 + (ch ^ 48);
return x * s;
}
ll mod_pow(ll x, ll y) {
ll res = 1;
for (; y; y >>= 1) {
if (y & 1)
res = res * x % MOD;
x = x * x % MOD;
}
return res;
}
ll inv2 = mod_pow(2, MOD - 2), inv6 = mod_pow(6, MOD - 2);
ll n, sqn;
ll v[N], primes[N], cnt, sp1[N], sp2[N], ind1[N], ind2[N], w[N], tot, g1[N],
g2[N];
void init(int s) {
memset(v, 0, sizeof(v));
memset(primes, 0, sizeof(primes));
memset(sp1, 0, sizeof(sp1));
memset(sp2, 0, sizeof(sp2));
memset(ind1, 0, sizeof(ind1));
memset(ind2, 0, sizeof(ind2));
memset(w, 0, sizeof(w));
memset(g1, 0, sizeof(g1));
memset(g2, 0, sizeof(g2));
cnt = tot = 0;
for (int i = 2; i <= s; ++i) {
if (!v[i]) {
v[i] = i, primes[++cnt] = i;
sp1[cnt] = (sp1[cnt - 1] + i) % MOD;
sp2[cnt] = (sp2[cnt - 1] + 1LL * i * i) % MOD;
}
for (int j = 1; j <= cnt && i * primes[j] <= s; ++j) {
v[i * primes[j]] = primes[j];
if (i % primes[j] == 0)
break;
}
}
}
// ll S(ll x, ll y) {
// if (primes[y] >= x)
// return 0;
// ll k = x <= sqn ? ind1[x] : ind2[n / x];
// // ll res = ((g2[k] - g1[k]) - (sp2[y] - sp1[y])) % MOD;
// ll res = (g2[k] - sp2[y]) % MOD;
// for (int i = y + 1; i <= cnt && primes[i] * primes[i] <= x; ++i) {
// ll pe = primes[i];
// for (ll e = 1; pe <= x; e++, pe = pe * primes[i]) {
// ll z = pe % MOD;
// res = res + z * z % MOD * (S(x / pe, i) + (e > 1));
// res %= MOD;
// }
// }
// return res;
// }
pair<ll, ll> solve(ll n) {
// freopen("1.in", "r", stdin);
// n = read();
sqn = sqrt(n);
init(sqn);
for (ll i = 1, j; i <= n; i = j + 1) {
j = n / (n / i);
w[++tot] = n / i;
g1[tot] = n / i % MOD;
g2[tot] =
g1[tot] * (g1[tot] + 1) % MOD * (2 * g1[tot] + 1) % MOD * inv6 % MOD -
1;
g1[tot] = g1[tot] * (g1[tot] + 1) / 2 % MOD - 1;
if (n / i <= sqn)
ind1[n / i] = tot;
else
ind2[n / (n / i)] = tot;
}
// for (int i = 1; i <= 20; ++i) {
// int k = w[i] <= sqn ? ind1[w[i]] : ind2[n / w[i]];
// cout << w[i] << ' ' << k << ' ' << g1[k] << ' ' << g2[k] << '\n';
// }
// cout << '\n';
for (int i = 1; i <= cnt; ++i) {
for (int j = 1; j <= tot && primes[i] * primes[i] <= w[j]; j++) {
ll k = w[j] / primes[i] <= sqn ? ind1[w[j] / primes[i]]
: ind2[n / (w[j] / primes[i])];
g1[j] -= primes[i] * (g1[k] - sp1[i - 1]);
g1[j] %= MOD;
g2[j] -= primes[i] * primes[i] % MOD * (g2[k] - sp2[i - 1]);
g2[j] %= MOD;
}
}
// printf("%lld\n", (S(n, 0) + 1 + MOD) % MOD);
int k = n <= sqn ? ind1[n] : ind2[n / n];
// printf("%lld\n", g2[k]);
// printf("%lld\n", g1[k]);
return {g1[k], g2[k]};
}
ll S1(ll x) {
return 1LL * (1 + x) * x % MOD * inv2 % MOD;
}
ll S1(ll x, ll y) {
return S1(y) - S1(x - 1);
}
ll S2(ll x) {
return 1LL * inv6 * x % MOD * (x + 1) % MOD * (2 * x + 1) % MOD;
}
ll S2(ll x, ll y) {
return S2(y) - S2(x - 1);
}
int main() {
// freopen("1.in", "r", stdin);
ll n = read();
ll L = n / 2 + 1;
ll R = n;
// p*p
// ll res = (solve(R) - solve(L - 1) + MOD) % MOD;
auto [x, y] = solve(R);
auto [_x, _y] = solve(L - 1);
ll sp = (x - _x + MOD) % MOD;
ll sp2 = (y - _y + MOD) % MOD;
// cout << "L, R, sp, sp2: " << L << ' ' << R << ' ' << sp << ' ' << sp2 << '\n';
ll s = (S1(2, n) - sp + MOD) % MOD;
ll ans = s * s % MOD;
ll r = (S2(2, n) - sp2 + MOD) % MOD;
ans = (ans - r + MOD) % MOD * inv2 % MOD;
ans = (ans + MOD) % MOD;
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 74080kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 3ms
memory: 74176kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 7ms
memory: 74180kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 7ms
memory: 74124kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 3ms
memory: 74084kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 4ms
memory: 74248kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 11ms
memory: 74096kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 8ms
memory: 74156kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 13ms
memory: 74044kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 3ms
memory: 74100kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 3ms
memory: 74188kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 7ms
memory: 74248kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 7ms
memory: 74104kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 8ms
memory: 74084kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 12ms
memory: 74044kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 8ms
memory: 74172kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 11ms
memory: 74004kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 4ms
memory: 74176kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 7ms
memory: 74248kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 7ms
memory: 74120kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 12ms
memory: 74004kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 16ms
memory: 74044kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 8ms
memory: 74104kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 12ms
memory: 74188kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 8ms
memory: 74060kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 3ms
memory: 74156kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 8ms
memory: 74160kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 32ms
memory: 74104kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 26ms
memory: 74188kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 29ms
memory: 74248kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 26ms
memory: 74116kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 34ms
memory: 74032kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 29ms
memory: 74032kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 27ms
memory: 74004kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 50ms
memory: 74032kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: -100
Wrong Answer
time: 83ms
memory: 74088kb
input:
3550627266
output:
605389926
result:
wrong answer 1st numbers differ - expected: '318019384', found: '605389926'