QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604479 | #8761. 另一个计数问题 | UESTC_Snow_Halation# | AC ✓ | 895ms | 34480kb | C++14 | 3.0kb | 2024-10-02 11:15:06 | 2024-10-02 11:15:06 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 2e6 + 7;
const ll M = 1e11;
const int Mod = 998244353;
ll Lim, lim;
ll lis[N];
int mp[N][2], cnt = 0, lpf[N], pcnt = 0, pri[N];
ll G[N][2], Fprime[N];
ll qpow(ll x, ll y)
{
if (y < 0)
return qpow(qpow(x, Mod - 2), -y);
ll ret = 1;
while (y)
{
if (y & 1)
ret = ret * x % Mod;
x = x * x % Mod, y >>= 1;
}
return ret;
}
const ll inv2 = qpow(2ll, Mod - 2);
const ll inv6 = qpow(6ll, Mod - 2);
inline const int Id(const ll &x)
{
return x <= lim ? mp[x][0] : mp[Lim / x][1];
}
// inline const ll f(const ll &x)
// {
// return x % Mod;
// }
// ll F(const ll n, const int k)
// {
// if (n < pri[k] || n <= 1)
// return 0;
// ll ans = (Fprime[Id(n)] - Fprime[Id(pri[k - 1])] + Mod) % Mod;
// for (int i = k; i <= pcnt && 1ll * pri[i] * pri[i] <= n; i++)
// for (ll pw = pri[i]; pw <= n / pri[i]; pw *= pri[i])
// ans = (ans + f(pw) * F(n / pw, i + 1) % Mod + f(pw * pri[i])) % Mod;
// return ans;
// }
int main()
{
cin >> Lim;
pri[0] = 1;
lim = sqrtl(Lim);
cnt = pcnt = 0;
for (int i = 2; i <= lim; i++)
lpf[i] = 0;
for (int i = 2; i <= lim; i++)
{
if (!lpf[i])
{
lpf[i] = ++pcnt;
pri[pcnt] = i;
}
for (int j = 1; j <= lpf[i] && 1ll * i * pri[j] <= lim; j++)
lpf[i * pri[j]] = j;
}
for (ll l = 1, r = 0, v; l <= Lim; l = r + 1)
{
r = Lim / (Lim / l);
lis[++cnt] = v = Lim / l;
(v <= lim ? mp[v][0] : mp[Lim / v][1]) = cnt;
G[cnt][0] = (v + 2ll) % Mod * ((v - 1ll) % Mod) % Mod * inv2 % Mod;
G[cnt][1] = v % Mod * ((v + 1) % Mod) % Mod * ((2ll * v + 1ll) % Mod) % Mod * inv6 % Mod;
G[cnt][1] = (G[cnt][1] + Mod - 1ll) % Mod;
}
ll v;
for (int k = 1; k <= pcnt; k++)
{
const ll pw = (ll)pri[k] * pri[k];
for (int i = 1; pw <= lis[i]; i++)
{
const int id1 = Id(lis[i] / pri[k]);
const int id2 = Id(pri[k - 1]);
G[i][0] = (G[i][0] - pri[k] * ((G[id1][0] - G[id2][0] + Mod) % Mod) % Mod + Mod) % Mod;
G[i][1] = (G[i][1] - 1ll * pri[k] * pri[k] % Mod * ((G[id1][1] - G[id2][1] + Mod) % Mod) % Mod + Mod) % Mod;
}
}
// cout << G[1][0] - G[2][0] << "\n";
// cout << G[1][1] - G[2][1] << "\n";
ll x1 = (G[1][0] - G[2][0] + Mod) % Mod;
ll x2 = (G[1][1] - G[2][1] + Mod) % Mod;
ll ans1 = (2ll + Lim) % Mod * ((Lim - 1) % Mod) % Mod * inv2 % Mod;
ans1 = (ans1 + Mod - x1) % Mod;
ans1 = ans1 * ans1 % Mod;
ll ans2 = Lim % Mod * ((Lim + 1) % Mod) % Mod * ((2ll * Lim + 1ll) % Mod) % Mod * inv6 % Mod;
ans2 = (ans2 + Mod - 1 - x2) % Mod;
ll ans = (ans1 - ans2 + Mod) % Mod * inv2 % Mod;
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13868kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 13880kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 13896kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 13816kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 0ms
memory: 13832kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 3ms
memory: 13808kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 3ms
memory: 14000kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 0ms
memory: 13808kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 0ms
memory: 13872kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 0ms
memory: 14000kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 0ms
memory: 13952kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 0ms
memory: 13868kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 0ms
memory: 13812kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 0ms
memory: 13880kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 0ms
memory: 13880kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 13808kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 0ms
memory: 13936kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 0ms
memory: 13796kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 0ms
memory: 13808kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 0ms
memory: 13868kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 0ms
memory: 13948kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 0ms
memory: 13948kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 0ms
memory: 13876kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 0ms
memory: 13864kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 0ms
memory: 13956kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 0ms
memory: 13892kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 0ms
memory: 13948kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 27ms
memory: 15860kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 31ms
memory: 15864kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 30ms
memory: 15956kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: 0
Accepted
time: 32ms
memory: 15952kb
input:
998244353
output:
326703895
result:
ok 1 number(s): "326703895"
Test #32:
score: 0
Accepted
time: 35ms
memory: 15928kb
input:
998244354
output:
730264864
result:
ok 1 number(s): "730264864"
Test #33:
score: 0
Accepted
time: 31ms
memory: 15924kb
input:
998244355
output:
539142451
result:
ok 1 number(s): "539142451"
Test #34:
score: 0
Accepted
time: 31ms
memory: 15924kb
input:
998244356
output:
751581014
result:
ok 1 number(s): "751581014"
Test #35:
score: 0
Accepted
time: 59ms
memory: 15948kb
input:
2165916141
output:
216013547
result:
ok 1 number(s): "216013547"
Test #36:
score: 0
Accepted
time: 78ms
memory: 15944kb
input:
3550627266
output:
318019384
result:
ok 1 number(s): "318019384"
Test #37:
score: 0
Accepted
time: 184ms
memory: 17848kb
input:
11640239920
output:
137498099
result:
ok 1 number(s): "137498099"
Test #38:
score: 0
Accepted
time: 241ms
memory: 24120kb
input:
16191777349
output:
991399721
result:
ok 1 number(s): "991399721"
Test #39:
score: 0
Accepted
time: 374ms
memory: 22092kb
input:
31326230483
output:
99981147
result:
ok 1 number(s): "99981147"
Test #40:
score: 0
Accepted
time: 382ms
memory: 24120kb
input:
32810385543
output:
284259680
result:
ok 1 number(s): "284259680"
Test #41:
score: 0
Accepted
time: 418ms
memory: 26160kb
input:
37368395332
output:
511468046
result:
ok 1 number(s): "511468046"
Test #42:
score: 0
Accepted
time: 440ms
memory: 24192kb
input:
40002331093
output:
282851705
result:
ok 1 number(s): "282851705"
Test #43:
score: 0
Accepted
time: 768ms
memory: 30264kb
input:
82884464396
output:
767050832
result:
ok 1 number(s): "767050832"
Test #44:
score: 0
Accepted
time: 866ms
memory: 32296kb
input:
96506992785
output:
31413975
result:
ok 1 number(s): "31413975"
Test #45:
score: 0
Accepted
time: 886ms
memory: 34284kb
input:
99999999995
output:
456189842
result:
ok 1 number(s): "456189842"
Test #46:
score: 0
Accepted
time: 895ms
memory: 34428kb
input:
99999999996
output:
516138273
result:
ok 1 number(s): "516138273"
Test #47:
score: 0
Accepted
time: 886ms
memory: 32248kb
input:
99999999997
output:
136420410
result:
ok 1 number(s): "136420410"
Test #48:
score: 0
Accepted
time: 884ms
memory: 34480kb
input:
99999999998
output:
841974696
result:
ok 1 number(s): "841974696"
Test #49:
score: 0
Accepted
time: 894ms
memory: 32308kb
input:
99999999999
output:
164762165
result:
ok 1 number(s): "164762165"
Test #50:
score: 0
Accepted
time: 886ms
memory: 34288kb
input:
100000000000
output:
627965619
result:
ok 1 number(s): "627965619"