QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#566565#9309. Graphfallleaves01AC ✓498ms19528kbC++202.8kb2024-09-16 00:31:542024-09-16 00:31:54

Judging History

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

  • [2024-09-16 00:31:54]
  • 评测
  • 测评结果:AC
  • 用时:498ms
  • 内存:19528kb
  • [2024-09-16 00:31:54]
  • 提交

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(ll 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[](ll i) { return i <= S ? vl[i] : vr[N / i]; }
    const ll& operator[](ll 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 *= (MInt(nn - 1 + mm).pow(nn - 2) * mm).pow(r - l + 1);
    }
    cout << int(ans) << '\n';
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 5ms
memory: 4016kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 18ms
memory: 4460kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 22ms
memory: 4376kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 37ms
memory: 5164kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 66ms
memory: 6668kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 165ms
memory: 11076kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 316ms
memory: 12876kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 457ms
memory: 19180kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 478ms
memory: 18260kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 498ms
memory: 19528kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 477ms
memory: 19272kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed