QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575368#9309. GraphpropaneWA 0ms3672kbC++203.3kb2024-09-19 13:18:282024-09-19 13:18:32

Judging History

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

  • [2024-09-19 13:18:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3672kb
  • [2024-09-19 13:18:28]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;

long long int_sqrt(long long x){
    long long ans = 0;
    for (long long k = 1LL << 30; k != 0; k /= 2){
        if ((ans + k) * (ans + k) <= x){
            ans += k;
        }
    }
    return ans;
}

LL prime_pi(const LL N) {
    if (N <= 1)
        return 0;

    if (N == 2)
        return 1;

    const int v = int_sqrt(N);
    int s = (v + 1) / 2;
    vector<int> smalls(s);

    for (int i = 1; i < s; ++i)
        smalls[i] = i;

    vector<int> roughs(s);

    for (int i = 0; i < s; ++i)
        roughs[i] = 2 * i + 1;

    vector<LL> larges(s);

    for (int i = 0; i < s; ++i)
        larges[i] = (N / (2 * i + 1) - 1) / 2;

    vector<bool> skip(v + 1);
    const auto divide = [](LL n, LL d) -> int { return double(n) / d; };
    const auto half = [](int n) -> int { return (n - 1) >> 1; };
    int pc = 0;

    for (int p = 3; p <= v; p += 2)
        if (!skip[p]) {
            int q = p * p;

            if (LL(q) * q > N)
                break;

            skip[p] = true;

            for (int i = q; i <= v; i += 2 * p)
                skip[i] = true;

            int ns = 0;

            for (int k = 0; k < s; ++k) {
                int i = roughs[k];

                if (skip[i])
                    continue;

                LL d = LL(i) * p;
                larges[ns] = larges[k] - (d <= v ? larges[smalls[d >> 1] - pc] : smalls[half(divide(N, d))]) + pc;
                roughs[ns++] = i;
            }

            s = ns;

            for (int i = half(v), j = ((v / p) - 1) | 1; j >= p; j -= 2) {
                int c = smalls[j >> 1] - pc;

                for (int e = (j * p) >> 1; i >= e; --i)
                    smalls[i] -= c;
            }

            ++pc;
        }

    larges[0] += LL(s + 2 * (pc - 1)) * (s - 1) / 2;

    for (int k = 1; k < s; ++k)
        larges[0] -= larges[k];

    for (int l = 1; l < s; ++l) {
        int q = roughs[l];
        LL M = N / q;
        int e = smalls[half(M / q)] - pc;

        if (e < l + 1)
            break;

        LL t = 0;

        for (int k = l + 1; k <= e; ++k)
            t += smalls[half(divide(M, roughs[k]))];

        larges[0] += t - LL(e - l) * (pc + l - 1);
    }

    return larges[0] + 1;
}

const int mod = 998244353;

int mul(int a, int b){
    return 1LL * a * b % mod;
}

int qpow(int a, LL b){
    int ans = 1;
    while(b){
        if (b & 1) ans = mul(ans, a);
        b >>= 1;
        a = mul(a, a);
    }
    return ans;
}

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    LL n;
    cin >> n;

    auto f = [&](LL m){
        if (m == 1) return 1;
        LL cnt = prime_pi(m) - prime_pi(m / 2);
        LL k = 1;
        k += cnt;
        if (m - cnt - 1 > 0) k += 1;
        int ans = qpow(m % mod, k - 2);
        ans = mul(ans, cnt % mod);
        if (m - cnt - 1 > 0) ans = mul(ans, (m - cnt - 1) % mod);
        return ans;
    };

    LL ans = 1;
    for(LL l = 1, r; l <= n; l = r + 1){
        r = n / (n / l);
        ans = mul(ans, qpow(f(n / l), r - l + 1));
    }
    cout << ans << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

443430910

result:

wrong answer expected '671840470', found '443430910'