QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#594152#9309. GraphcaojcWA 1ms3804kbC++203.2kb2024-09-27 19:43:012024-09-27 19:43:03

Judging History

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

  • [2024-09-27 19:43:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3804kb
  • [2024-09-27 19:43:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>

#define db(args...) { \
     string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
     stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << ' ';
    err(++it, args...);
}



/*
min25筛第一部分,求质数的多项式和。
 */
vector<int> visi, pri; int cpri;
void init(int N) {
    N++;
    visi.assign(N, 0), pri.assign(N, 0);
    for (int i = 2; i < N; i++) {
        if (!visi[i]) {
            visi[i] = i;
            pri[++cpri] = i;
        }
        for (int j = 1; j <= cpri; j++) {
            int id = pri[j] * i;
            if (id >= N) break;
            visi[id] = pri[j];
            if (i % pri[j] == 0) break;
        }
    }
}
struct min25 {
    // 幂次k=1
    ll sn, n;
    vector<int> id;
    vector<ll> g;
    int getid(ll x) {
        if (x <= sn) return x;
        return id[n / x];
    }
    min25(ll N) {
        n = N;
        sn = sqrt((long double)n);
        init(2 * sn + 10); // todo

        id.assign(sn + 1, 0);
        g.assign(sn * 2 + 1, 0);
        vector<ll> big(sn * 2 + 1), G(sn + 1);
        
        for (int i = 2; i <= sn; i++) {
            G[i] = G[i - 1] + (visi[i] == i);
        }
        for (int i = 1; i <= sn; i++) {
            id[i] = 2 * sn + 1 - i;
            big[i] = i, big[id[i]] = n / i;
        }

        for (int i = 1; i <= sn * 2; i++) {
            g[i] = big[i] - 1; // todo 除了1所有数的k次方前缀和
        }

        for (int j = 1, beg = 1; pri[j] <= sn; j++) {
            while (j > 1 && beg <= sn * 2 && pri[j] * 1ll * pri[j] > big[beg]) beg++;
            for (int i = sn * 2; i >= beg; i--) {
                ll k = 1; // todo pri[j] ^ k
                g[i] = g[i] - k * (g[getid(big[i] / pri[j])] - G[pri[j - 1]]);
            }
        }
    }
    ll get(ll n) {
        return g[getid(n)];
    }
};

const int mod = 998244353;
ll ksm(ll a, ll b = mod - 2) {
    a %= mod;
    if (b == -1) return ksm(a);
    ll res = 1;
    while (b) {
        if (b) res = res * a % mod;
        a = a * a % mod, b /= 2;
    }
    return res;
}
void solve() {
    ll n;
    cin >> n;

    min25 mi(n);

    auto f = [&] (ll n) ->ll {
        if (n <= 2) return 1;
        ll c = mi.get(n) % mod - mi.get(n / 2) % mod;
        c = (c + mod) % mod;
        
        if (c == 0) return 1;
        c++;
        ll k = c + 1;
        ll res = (n - c) * ksm(n, k - 2) % mod;
        // db(n, res, c);
        return res;
    };

    ll res = 1;
    for (ll l = 1, r; l <= n; l = r + 1) {
        r = n / (n / l);
        
        ll resi = ksm(f(n / l), r - l + 1);
        res = res * resi % mod;
    }
    cout << res << '\n';
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

/*
g++ 1.cpp -std=c++20 -o 1 && ./1 < in.txt > out.txt
 */

詳細信息

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3732kb

input:

123

output:

0

result:

wrong answer expected '671840470', found '0'