QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604478#8761. 另一个计数问题UESTC_Snow_Halation#RE 411ms24088kbC++143.0kb2024-10-02 11:14:132024-10-02 11:14:13

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 11:14:13]
  • 评测
  • 测评结果:RE
  • 用时:411ms
  • 内存:24088kb
  • [2024-10-02 11:14:13]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef double db;

const int N = 5e5 + 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: 2ms
memory: 13856kb

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 0ms
memory: 13840kb

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: 0
Accepted
time: 2ms
memory: 13840kb

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

score: 0
Accepted
time: 1ms
memory: 13744kb

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

score: 0
Accepted
time: 0ms
memory: 13848kb

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

score: 0
Accepted
time: 1ms
memory: 13840kb

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

score: 0
Accepted
time: 1ms
memory: 13952kb

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

score: 0
Accepted
time: 1ms
memory: 13892kb

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

score: 0
Accepted
time: 0ms
memory: 13844kb

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

score: 0
Accepted
time: 1ms
memory: 13848kb

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

score: 0
Accepted
time: 1ms
memory: 13808kb

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

score: 0
Accepted
time: 0ms
memory: 13792kb

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

score: 0
Accepted
time: 1ms
memory: 13908kb

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

score: 0
Accepted
time: 1ms
memory: 13860kb

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

score: 0
Accepted
time: 1ms
memory: 13844kb

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

score: 0
Accepted
time: 0ms
memory: 13876kb

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

score: 0
Accepted
time: 0ms
memory: 13888kb

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

score: 0
Accepted
time: 0ms
memory: 11828kb

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

score: 0
Accepted
time: 0ms
memory: 13872kb

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

score: 0
Accepted
time: 1ms
memory: 13940kb

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

score: 0
Accepted
time: 2ms
memory: 13852kb

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

score: 0
Accepted
time: 0ms
memory: 13852kb

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

score: 0
Accepted
time: 1ms
memory: 13952kb

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

score: 0
Accepted
time: 1ms
memory: 11908kb

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

score: 0
Accepted
time: 1ms
memory: 13900kb

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

score: 0
Accepted
time: 0ms
memory: 13904kb

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

score: 0
Accepted
time: 2ms
memory: 13848kb

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: 0
Accepted
time: 32ms
memory: 15860kb

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

score: 0
Accepted
time: 33ms
memory: 13904kb

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

score: 0
Accepted
time: 33ms
memory: 15948kb

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

score: 0
Accepted
time: 32ms
memory: 15900kb

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

score: 0
Accepted
time: 28ms
memory: 16000kb

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 28ms
memory: 15948kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

score: 0
Accepted
time: 29ms
memory: 15920kb

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

score: 0
Accepted
time: 51ms
memory: 15892kb

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: 0
Accepted
time: 73ms
memory: 15900kb

input:

3550627266

output:

318019384

result:

ok 1 number(s): "318019384"

Test #37:

score: 0
Accepted
time: 176ms
memory: 20016kb

input:

11640239920

output:

137498099

result:

ok 1 number(s): "137498099"

Test #38:

score: 0
Accepted
time: 221ms
memory: 20056kb

input:

16191777349

output:

991399721

result:

ok 1 number(s): "991399721"

Test #39:

score: 0
Accepted
time: 348ms
memory: 22096kb

input:

31326230483

output:

99981147

result:

ok 1 number(s): "99981147"

Test #40:

score: 0
Accepted
time: 361ms
memory: 24088kb

input:

32810385543

output:

284259680

result:

ok 1 number(s): "284259680"

Test #41:

score: 0
Accepted
time: 395ms
memory: 22584kb

input:

37368395332

output:

511468046

result:

ok 1 number(s): "511468046"

Test #42:

score: 0
Accepted
time: 411ms
memory: 24088kb

input:

40002331093

output:

282851705

result:

ok 1 number(s): "282851705"

Test #43:

score: -100
Runtime Error

input:

82884464396

output:


result: