QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129667#6740. FunctionUndertrainedOverpressure#AC ✓271ms3992kbC++233.4kb2023-07-22 21:56:522023-07-22 21:57:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 21:57:02]
  • 评测
  • 测评结果:AC
  • 用时:271ms
  • 内存:3992kb
  • [2023-07-22 21:56:52]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

// если модуль подается на вход, убрать все <> и раскомментировать нужные строки
using uint = unsigned int;
using ull = unsigned long long;
template <uint MD> struct ModInt {
    using M = ModInt;
    // static int MD;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint((ull)v * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    bool operator!=(const M& r) const { return v != r.v; }
    M inv() const;
    friend istream& operator>>(istream& is, M& r) { ll x; is >> x; r = M(x); return is; }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};

template<uint MD>
ModInt<MD> pow(ModInt<MD> x, ll n) {
    ModInt<MD> r = 1;
    while (n) {
        if (n & 1) r *= x;
        x *= x;
        n >>= 1;
    }
    return r;
}

template<uint MD>
ModInt<MD> ModInt<MD>::inv() const { return pow(*this, MD - 2); }
// or copy egcd and {return egcd(MD, v, 1).second;}

// if MD is from input
// this line is necessary, read later as you wish
// int ModInt::MD;

using Mint = ModInt<998244353>;
// using Mint = double;

const int R = 20210926;
const int M = 50010;

int n;
Mint f1[M];
Mint f2[M];

void solve() {
    cin >> n;
    if (n <= 3) {
        cout << n << "\n";
        return;
    }
    int p = 1;
    while ((p + 1) * (p + 1) <= n) {
        p++;
    }
    f1[1] = 1;
    for (int d = 2; d <= p; d++) {
        int x = (n / d);
        Mint ans = 1;
        int k = 2;
        while (k <= R && k * x <= n) {
            int cur_d = n / (k * x);
            int rk = (n / (cur_d * x));
            rk = min(rk, R);
            ans += f1[cur_d] * (rk - k + 1);
            k = rk + 1;
        }
        f1[d] = ans;
    }
    int rgt = (n / (p + 1));
    for (int x = rgt; x >= 1; x--) {
        Mint ans = 1;
        int k = 2;
        while (k <= R && k * x <= n) {
            if (k * x > rgt) {
                int cur_d = n / (k * x);
                int rk = (n / (cur_d * x));
                rk = min(rk, R);
                ans += f1[cur_d] * (rk - k + 1);
                k = rk + 1;
            } else {
                ans += f2[k * x];
                k++;
            }
        }
        f2[x] = ans;
    }
    cout << f2[1] << "\n";
}

int main() {
#ifdef ONPC
    freopen("input", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3864kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

100

output:

949

result:

ok 1 number(s): "949"

Test #4:

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

input:

10

output:

19

result:

ok 1 number(s): "19"

Test #5:

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

input:

1000

output:

48614

result:

ok 1 number(s): "48614"

Test #6:

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

input:

10000

output:

2602393

result:

ok 1 number(s): "2602393"

Test #7:

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

input:

100000

output:

139804054

result:

ok 1 number(s): "139804054"

Test #8:

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

input:

1000000

output:

521718285

result:

ok 1 number(s): "521718285"

Test #9:

score: 0
Accepted
time: 10ms
memory: 3856kb

input:

10000000

output:

503104917

result:

ok 1 number(s): "503104917"

Test #10:

score: 0
Accepted
time: 49ms
memory: 3848kb

input:

100000000

output:

198815604

result:

ok 1 number(s): "198815604"

Test #11:

score: 0
Accepted
time: 267ms
memory: 3856kb

input:

1000000000

output:

373787809

result:

ok 1 number(s): "373787809"

Test #12:

score: 0
Accepted
time: 270ms
memory: 3816kb

input:

999999999

output:

997616263

result:

ok 1 number(s): "997616263"

Test #13:

score: 0
Accepted
time: 266ms
memory: 3808kb

input:

999999990

output:

997615701

result:

ok 1 number(s): "997615701"

Test #14:

score: 0
Accepted
time: 270ms
memory: 3972kb

input:

999999900

output:

993928691

result:

ok 1 number(s): "993928691"

Test #15:

score: 0
Accepted
time: 271ms
memory: 3868kb

input:

999999000

output:

754532207

result:

ok 1 number(s): "754532207"

Test #16:

score: 0
Accepted
time: 266ms
memory: 3916kb

input:

999990000

output:

996592686

result:

ok 1 number(s): "996592686"

Test #17:

score: 0
Accepted
time: 270ms
memory: 3856kb

input:

999900000

output:

311678722

result:

ok 1 number(s): "311678722"

Test #18:

score: 0
Accepted
time: 269ms
memory: 3924kb

input:

999000000

output:

60462624

result:

ok 1 number(s): "60462624"

Test #19:

score: 0
Accepted
time: 267ms
memory: 3808kb

input:

990000000

output:

444576800

result:

ok 1 number(s): "444576800"

Test #20:

score: 0
Accepted
time: 249ms
memory: 3852kb

input:

900000000

output:

95615129

result:

ok 1 number(s): "95615129"

Test #21:

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

input:

1361956

output:

813433539

result:

ok 1 number(s): "813433539"

Test #22:

score: 0
Accepted
time: 8ms
memory: 3848kb

input:

7579013

output:

677659797

result:

ok 1 number(s): "677659797"

Test #23:

score: 0
Accepted
time: 8ms
memory: 3992kb

input:

8145517

output:

801509527

result:

ok 1 number(s): "801509527"

Test #24:

score: 0
Accepted
time: 7ms
memory: 3872kb

input:

6140463

output:

869023935

result:

ok 1 number(s): "869023935"

Test #25:

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

input:

3515281

output:

989091505

result:

ok 1 number(s): "989091505"

Test #26:

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

input:

6969586

output:

539840131

result:

ok 1 number(s): "539840131"