QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585783#8761. 另一个计数问题yangylWA 0ms3828kbC++202.2kb2024-09-23 22:09:272024-09-23 22:09:31

Judging History

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

  • [2024-09-23 22:09:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2024-09-23 22:09:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
using ll = long long;
constexpr int P = 998244353;
constexpr int inv2 = 499122177, inv6 = 166374059;
constexpr int N = 1e5 + 5;
bool st[N];
vector<int> p;

void seive(int n) {
    for (int i = 2; i <= n; i++) {
        if (!st[i]) {
            p.push_back(i);
        }
        for (int j = 0; j < p.size() && i * p[j] <= n; j++) {
            st[i * p[j]] = true;
            if (i % p[j] == 0) break;
        }
    }
}

void inc(int &a, int b) {
    a += b;
    if (a >= P) {
        a -= P;
    } else if (a < 0) {
        a += P;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;

    int S1 = 1LL * (n + 1) % P * n % P * inv2 % P;
    inc(S1, -1);
    int S2 = 1LL * n % P * (n + 1) % P * (2 * n + 1) % P * inv6 % P;
    inc(S2, -1);

    vector<ll> v;
    for (ll l = 1, r; l <= n; l = r + 1) {
        r = n / (n / l);
        v.push_back(n / l);
    }
    int sq = sqrt(n);
    seive(sq);

    vector<int> g1(v.size()), g2(v.size());
    auto get = [&](const vector<int> &g, int x) {
        if (x <= sq) {
            return g[v.size() - x];
        } else {
            return g[n / x - 1];
        }
    };

    for (int i = 0; i < v.size(); i++) {
        int x = v[i];
        g1[i] = 1LL * x % P * (x + 1) % P * inv2 % P;
        inc(g1[i], -1);
        g2[i] = 1LL * x % P * (x + 1) % P * (2 * x + 1) % P * inv6 % P;
        inc(g2[i], -1);
    }

    int sp1 = 0, sp2 = 0;
    for (auto x : p) {
        for (int i = 0; i < v.size(); i++) {
            if (1LL * x * x > v[i]) {
                break;
            }
            inc(g1[i], -(1LL * x * (get(g1, v[i] / x) - sp1 + P) % P));
            inc(g2[i], -(1LL * x * x % P * (get(g2, v[i] / x) - sp2 + P) % P));
        }
        inc(sp1, x);
        inc(sp2, 1LL * x * x % P);
    }

    int ans = 1LL * (S1 * S1 % P - S2 + P) % P * inv2 % P;
    int v1 = g1[0], v2 = g2[0];
    inc(v1, -get(g1, n / 2));
    inc(v2, -get(g2, n / 2));
    inc(S1, -v1);
    inc(ans, -(v1 * S1 % P));
    v1 = 1LL * v1 * v1 % P;
    inc(v1, -v2);
    v1 = 1LL * v1 * inv2 % P;
    inc(ans, -v1);
    cout << ans << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

score: -100
Wrong Answer
time: 0ms
memory: 3620kb

input:

355

output:

358868178

result:

wrong answer 1st numbers differ - expected: '509863120', found: '358868178'