QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575372#9309. GraphpropaneTL 2630ms4356kbC++203.3kb2024-09-19 13:20:402024-09-19 13:20:41

Judging History

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

  • [2024-09-19 13:20:41]
  • 评测
  • 测评结果:TL
  • 用时:2630ms
  • 内存:4356kb
  • [2024-09-19 13:20:40]
  • 提交

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);
        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: 3836kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 41ms
memory: 3880kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 240ms
memory: 3732kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 240ms
memory: 3664kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 440ms
memory: 3836kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 880ms
memory: 4036kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 2630ms
memory: 4356kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: -100
Time Limit Exceeded

input:

52500109238

output:


result: