QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125295#6740. Functionhos_lyricAC ✓498ms3708kbC++145.5kb2023-07-16 14:59:282023-07-16 14:59:29

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-16 14:59:29]
  • 评测
  • 测评结果:AC
  • 用时:498ms
  • 内存:3708kb
  • [2023-07-16 14:59:28]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


inline long long divide(long long a, int b) {
  return static_cast<double>(a) / b;
}
inline long long divide(long long a, long long b) {
  return static_cast<double>(a) / b;
}

struct Quotients {
  long long N;
  int N2, N3, N4, N6;
  int len;
  Quotients(long long N_ = 0) : N(N_) {
    N2 = sqrt(static_cast<long double>(N));
    N3 = cbrt(static_cast<long double>(N));
    for (; static_cast<long long>(N3) * N3 * N3 < N; ++N3) {}
    for (; static_cast<long long>(N3) * N3 * N3 > N; --N3) {}
    N4 = sqrt(static_cast<long double>(N2));
    N6 = sqrt(static_cast<long double>(N3));
    len = 2 * N2 + ((static_cast<long long>(N2) * (N2 + 1) <= N) ? 1 : 0);
  }
  long long operator[](int i) const {
    return (i <= N2) ? i : divide(N, len - i);
  }
  int indexOf(long long x) const {
    return (x <= N2) ? x : (len - divide(N, x));
  }
  friend std::ostream &operator<<(std::ostream &os, const Quotients &quo) {
    os << "[";
    for (int i = 0; i < quo.len; ++i) {
      if (i > 0) os << ", ";
      os << quo[i];
    }
    os << "]";
    return os;
  }
};


/*
  f(x) = [x <= n] (1 + \sum[1<k<=K] f(k x))
  g(N/x) := f(x)
  g(x) = [x >= 1] (1 + \sum[1<k<=K] g(x/k))
*/

constexpr Int K = 20210926;

int main() {
  Int N;
  for (; ~scanf("%lld", &N); ) {
    Quotients quo(N);
// cerr<<"|quo| = "<<quo.len<<", quo = "<<quo<<endl;
    vector<Mint> dp(quo.len);
    for (int i = 1; i < quo.len; ++i) {
      dp[i] = 1;
      const Int n = quo[i];
      for (Int a = 0, b; a < n; a = b) {
        const Int k = divide(n, a + 1);
        b = divide(n, k);
        // (a, b]: k
        const Int lb = max(a, 1LL);
        const Int ub = min(b, K);
        if (lb < ub) {
          dp[i] += (ub - lb) * dp[quo.indexOf(k)];
        }
      }
    }
    printf("%u\n", dp.back().x);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

100

output:

949

result:

ok 1 number(s): "949"

Test #4:

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

input:

10

output:

19

result:

ok 1 number(s): "19"

Test #5:

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

input:

1000

output:

48614

result:

ok 1 number(s): "48614"

Test #6:

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

input:

10000

output:

2602393

result:

ok 1 number(s): "2602393"

Test #7:

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

input:

100000

output:

139804054

result:

ok 1 number(s): "139804054"

Test #8:

score: 0
Accepted
time: 4ms
memory: 3680kb

input:

1000000

output:

521718285

result:

ok 1 number(s): "521718285"

Test #9:

score: 0
Accepted
time: 17ms
memory: 3708kb

input:

10000000

output:

503104917

result:

ok 1 number(s): "503104917"

Test #10:

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

input:

100000000

output:

198815604

result:

ok 1 number(s): "198815604"

Test #11:

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

input:

1000000000

output:

373787809

result:

ok 1 number(s): "373787809"

Test #12:

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

input:

999999999

output:

997616263

result:

ok 1 number(s): "997616263"

Test #13:

score: 0
Accepted
time: 494ms
memory: 3684kb

input:

999999990

output:

997615701

result:

ok 1 number(s): "997615701"

Test #14:

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

input:

999999900

output:

993928691

result:

ok 1 number(s): "993928691"

Test #15:

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

input:

999999000

output:

754532207

result:

ok 1 number(s): "754532207"

Test #16:

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

input:

999990000

output:

996592686

result:

ok 1 number(s): "996592686"

Test #17:

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

input:

999900000

output:

311678722

result:

ok 1 number(s): "311678722"

Test #18:

score: 0
Accepted
time: 497ms
memory: 3628kb

input:

999000000

output:

60462624

result:

ok 1 number(s): "60462624"

Test #19:

score: 0
Accepted
time: 490ms
memory: 3628kb

input:

990000000

output:

444576800

result:

ok 1 number(s): "444576800"

Test #20:

score: 0
Accepted
time: 456ms
memory: 3628kb

input:

900000000

output:

95615129

result:

ok 1 number(s): "95615129"

Test #21:

score: 0
Accepted
time: 4ms
memory: 3644kb

input:

1361956

output:

813433539

result:

ok 1 number(s): "813433539"

Test #22:

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

input:

7579013

output:

677659797

result:

ok 1 number(s): "677659797"

Test #23:

score: 0
Accepted
time: 11ms
memory: 3708kb

input:

8145517

output:

801509527

result:

ok 1 number(s): "801509527"

Test #24:

score: 0
Accepted
time: 12ms
memory: 3640kb

input:

6140463

output:

869023935

result:

ok 1 number(s): "869023935"

Test #25:

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

input:

3515281

output:

989091505

result:

ok 1 number(s): "989091505"

Test #26:

score: 0
Accepted
time: 13ms
memory: 3704kb

input:

6969586

output:

539840131

result:

ok 1 number(s): "539840131"