QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575411 | #8761. 另一个计数问题 | caojc | AC ✓ | 1536ms | 41292kb | C++20 | 3.9kb | 2024-09-19 13:56:05 | 2024-09-19 13:56:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define int long long
#define db(args...) { \
string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << ' ';
err(++it, args...);
}
const int mod = 998244353;
ll ksm(ll a, ll b = mod - 2) {
a %= mod;
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod, b /= 2;
}
return res;
}
ll i2, i6;
ll s1(ll n) {
n %= mod;
return (1 + n) * n % mod * i2 % mod;
}
ll s1(ll l, ll r) {
return (s1(r) - s1(l - 1) + mod) % mod;
}
ll s2(ll n) {
n %= mod;
return n * (n + 1) % mod * (2 * n + 1) % mod * i6 % mod;
}
ll s2(ll l, ll r) {
return (s2(r) - s2(l - 1) + mod) % mod;
}
/*
min25筛第一部分,求质数的多项式和。
*/
vector<int> visi, pri; int cpri;
void init(int N) {
N++; cpri = 0;
visi.assign(N, 0), pri.assign(N, 0);
for (int i = 2; i < N; i++) {
if (!visi[i]) {
visi[i] = i;
pri[++cpri] = i;
}
for (int j = 1; j <= cpri; j++) {
int id = pri[j] * i;
if (id >= N) break;
visi[id] = pri[j];
if (i % pri[j] == 0) break;
}
}
}
struct min25 {
// 幂次k=1
ll sn, n;
vector<int> id;
vector<ll> g;
int getid(ll x) {
if (x <= sn) return x;
return id[n / x];
}
min25(ll N, int k) {
n = N;
sn = sqrt((long double)n);
init(1e6); // todo
id.assign(sn + 1, 0);
g.assign(sn * 2 + 1, 0);
vector<ll> big(sn * 2 + 1), G(sn + 1);
for (int i = 2; i <= sn; i++) {
G[i] = G[i - 1] + ((visi[i] == i) * ksm(i, k));
g[i] %= mod;
}
for (int i = 1; i <= sn; i++) {
id[i] = 2 * sn + 1 - i;
big[i] = i, big[id[i]] = n / i;
}
for (int i = 1; i <= sn * 2; i++) {
if (k == 0) g[i] = big[i] - 1; // todo 除了1所有数的k次方前缀和
if (k == 1) g[i] = (s1(big[i]) - 1 + mod) % mod;
if (k == 2) g[i] = (s2(big[i]) - 1 + mod) % mod;
}
for (int j = 1, beg = 1; pri[j] <= sn; j++) {
while (j > 1 && beg <= sn * 2 && pri[j] * 1ll * pri[j] > big[beg]) beg++;
for (int i = sn * 2; i >= beg; i--) {
ll v = ksm(pri[j], k); // todo pri[j] ^ k
g[i] = g[i] - v * ((g[getid(big[i] / pri[j])] - G[pri[j - 1]] + mod) % mod) % mod;
g[i] = (g[i] % mod + mod) % mod;
}
}
}
ll get(ll n) {
return g[getid(n)];
}
};
void solve() {
i2 = ksm(2), i6 = ksm(6);
ll n;
cin >> n;
ll ans1 = 0;
ans1 = (s1(2, n / 2) * s1(2, n / 2) % mod - s2(2, n / 2) + mod) % mod * i2 % mod;
min25 m1(n, 1);
min25 m2(n, 2);
ll v1 = s1(2, n / 2), v2 = (s1(n / 2 + 1, n) - (m1.get(n) - m1.get(n / 2)));
v2 = (v2 % mod + mod) % mod;
ll ans2 = v1 * v2;
ans2 = (ans2 % mod + mod) % mod;
ll v = s1(n / 2 + 1, n) - (m1.get(n) - m1.get(n / 2));
v = (v % mod + mod) % mod;
ll ans3 = (v * v % mod - (s2(n / 2 + 1, n) - m2.get(n) + m2.get(n / 2)));
ans3 = (ans3 % mod + mod) % mod;
ans3 = ans3 * i2 % mod;
ll ans = ans1 + ans2 + ans3;
ans = (ans % mod + mod) % mod;
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
/*
g++ 1.cpp -std=c++20 -o 1 && ./1 < in.txt > out.txt
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 19040kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 7ms
memory: 18732kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 12ms
memory: 18992kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 7ms
memory: 18872kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 8ms
memory: 18892kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 8ms
memory: 18924kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 12ms
memory: 18720kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 8ms
memory: 18800kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 7ms
memory: 18728kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 7ms
memory: 18732kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 7ms
memory: 18908kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 8ms
memory: 18700kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 12ms
memory: 18976kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 6ms
memory: 18764kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 12ms
memory: 18740kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 8ms
memory: 18796kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 8ms
memory: 18868kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 12ms
memory: 18968kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 11ms
memory: 18924kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 12ms
memory: 18884kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 7ms
memory: 18924kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 10ms
memory: 18868kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 8ms
memory: 18908kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 8ms
memory: 18884kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 13ms
memory: 18908kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 8ms
memory: 18896kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 8ms
memory: 18812kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 72ms
memory: 21088kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 68ms
memory: 21076kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 67ms
memory: 20888kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 67ms
memory: 21168kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 68ms
memory: 20892kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 68ms
memory: 20908kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 67ms
memory: 20912kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 110ms
memory: 22124kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 153ms
memory: 23136kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 340ms
memory: 26592kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 422ms
memory: 27836kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 683ms
memory: 31184kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 699ms
memory: 31640kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 768ms
memory: 32348kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 805ms
memory: 32880kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 1343ms
memory: 39004kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 1494ms
memory: 40452kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 1528ms
memory: 41092kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 1536ms
memory: 41096kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 1528ms
memory: 41044kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 1532ms
memory: 41292kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 1527ms
memory: 40932kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 1528ms
memory: 41212kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"