QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566448#9309. Graphfallleaves01WA 0ms3792kbC++202.8kb2024-09-16 00:08:512024-09-16 00:08:53

Judging History

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

  • [2024-09-16 00:08:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3792kb
  • [2024-09-16 00:08:51]
  • 提交

answer

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

template <int P>
int mod(int v) {
    return (v < 0) ? (v + P) : (v < P ? v : (v - P));
}

template <int P>
struct ModInt {
    int v;
    ModInt(int val = 0) : v(mod<P>(val)) {}
    ModInt(ll val) : v(mod<P>(val % P)) {}
    ModInt& operator+=(const ModInt& b) {
        if ((v += b.v) >= P) {
            v -= P;
        }
        return *this;
    }
    ModInt& operator-=(const ModInt& b) {
        if ((v -= b.v) < 0) {
            v += P;
        }
        return *this;
    }
    ModInt& operator*=(const ModInt& b) {
        v = 1ll * v * b.v % P;
        return *this;
    }
    friend ModInt operator+(ModInt a, const ModInt& b) { return a += b; }
    friend ModInt operator-(ModInt a, const ModInt& b) { return a -= b; }
    friend ModInt operator*(ModInt a, const ModInt& b) { return a *= b; }

    ModInt pow(int b) const {
        if (b < 0) {
            (b %= P - 1) += P - 1;
        }
        ModInt c = 1, a = *this;
        for (; b; b >>= 1, a *= a) {
            if (b & 1) {
                c *= a;
            }
        }
        return c;
    }
    explicit operator int() const { return v; }
};
using MInt = ModInt<998244353>;

struct Arr {
    const ll N, S;
    vector<ll> vl, vr;
    Arr(ll n) : N(n), S(sqrtl(n)), vl(S + 1), vr(S + 1) {}
    ll& operator[](int i) { return i <= S ? vl[i] : vr[N / i]; }
    const ll& operator[](int i) const { return i <= S ? vl[i] : vr[N / i]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    ll n;
    cin >> n;
    ll s = sqrtl(n);
    vector<int> vis(s + 1), pri;
    for (int i = 2; i <= s; i++) {
        if (!vis[i]) {
            pri.emplace_back(i);
        }
        for (auto p : pri) {
            if (1ll * i * p > s) {
                break;
            }
            vis[i * p] = true;
            if (i % p == 0) {
                break;
            }
        }
    }
    vector<ll> val;
    Arr f(n);
    for (ll i = 1; i <= n; i++) {
        val.emplace_back(n / i);
        f[val.back()] = val.back() - 1;
        i = n / (n / i);
    }
    for (int i = 0; i < (int)pri.size(); i++) {
        for (auto v : val) {
            if (1ll * pri[i] * pri[i] > v) {
                break;
            }
            f[v] -= f[v / pri[i]] - i;
        }
    }
    // cout << int(f[n]) << '\n';
    MInt ans = 1;
    for (ll l = 1, r; l <= n; l = r + 1) {
        ll d = n / l;
        r = n / d;
        if (d <= 2) {
        	continue;
        }
        auto nn = f[d] - f[d / 2] + 2;
        auto mm = d - nn + 1;
        if (mm == 0) {
        	mm = 1, nn--;
        }
        ans *= (r - l + 1) * MInt(nn - 1 + mm).pow(nn - 2) * mm;
    }
    cout << int(ans) << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

933844287

result:

wrong answer expected '671840470', found '933844287'