QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575519#9309. GraphcaojcWA 0ms3716kbC++203.1kb2024-09-19 15:01:432024-09-19 15:01:43

Judging History

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

  • [2024-09-19 15:01:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3716kb
  • [2024-09-19 15:01:43]
  • 提交

answer

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

#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...);
}


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

/*
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)];
    }
};

void solve() {
    ll n;
    cin >> n;

    min25 mi(n);

    unordered_map<ll, ll> mp;
    function<ll(ll)> wk = [&] (ll n)->ll {
        if (n <= 2) return 1;
        auto it = mp.find(n);
        if (it != mp.end()) return it->second;

        ll c = mi.get(n) - mi.get(n / 2); 
        ll res = ksm(n, c) * ((n - c - 1 + mod) % mod) % mod;
        for (ll l = 2, r; l <= n; l = r + 1) {
            r = n / (n / l);
            res = res * ksm(wk(n / l), r - l + 1) % mod;
        }
        return mp[n] = res;
    };
    cout << wk(n) << '\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: 3588kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

0

result:

wrong answer expected '671840470', found '0'