QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733151#9515. 无限地狱JWRuixi55 290ms47564kbC++203.4kb2024-11-10 17:26:412024-11-10 17:26:42

Judging History

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

  • [2024-11-10 17:26:42]
  • 评测
  • 测评结果:55
  • 用时:290ms
  • 内存:47564kb
  • [2024-11-10 17:26:41]
  • 提交

answer

#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define me(f, x) memset(f, x, sizeof(f))
#define mc(f, g) memcpy(f, g, sizeof(f))
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

constexpr int P = 998244353;

IL void qm (int &x) {
  x += x >> 31 & P;
}

IL void pls (int &x, const LL &y) {
  x = (x + y) % P;
}

constexpr int SQ = 1 << 18;

template<int base>
struct gsm {
  int a[SQ + 3], b[SQ + 3];
  
  gsm () {
    a[0] = b[0] = 1;
    L (i, 1, SQ) {
      a[i] = (LL)base * a[i - 1] % P;
    }
    L (i, 1, SQ) {
      b[i] = (LL)a[SQ] * b[i - 1] % P;
    }
  }

  int operator () (LL k) const {
    return (LL)a[k & (SQ - 1)] * b[k >> 18] % P;
  }
};

gsm<2> p2;

constexpr int N = 2e6;
constexpr int M = 1e4;

LL n;

int mu[N + 3], p[N / 10 + 3], cnt;
bool np[N + 3];

int pmu[N + 3], smu[N + 3];
int f[N + 3], fp[N + 3];
int g[N + 3], gp[N + 3];
int h[N + 3], hp[N + 3];

int tot;
LL idx[M + 3];

IL int Mu (LL x) {
  return x <= N ? pmu[x] : smu[n / x];
}

IL int W (LL x) {
  return (P - 2LL + p2(x / 2 + 1) + p2((x + 1) / 2)) % P;
}

IL int F (LL x) {
  return x <= N ? f[x] : fp[n / x];
}

IL int G (LL x) {
  return x <= N ? g[x] : gp[n / x];
}

IL int H (LL x) {
  return x <= N ? h[x] : hp[n / x];
}

void init () {
  mu[1] = 1;
  L (i, 2, N) {
    if (!np[i]) {
      p[++cnt] = i;
      mu[i] = -1;
    }
    for (int j = 1; j <= cnt && i * p[j] <= N; ++j) {
      np[i * p[j]] = 1;
      if (i % p[j] == 0) {
        break;
      }
      mu[i * p[j]] = -mu[i];
    }
  }
  L (i, 1, N) {
    pmu[i] = (pmu[i - 1] + P + mu[i]) % P;
  }
  L (i, 1, N) {
    if (i > 1) {
      int x = f[i] + p2(i - 2);
      L (j, 1, N / i) if (mu[j]) {
        pls(g[i * j], (P + 6LL * mu[j]) * x);
        pls(h[i * j], (P + 3LL * mu[j]) * x);
      }
    }
    pls(g[i], (P - 2LL) * f[i] + P - p2(i - 1) + 2 * mu[i]);
    pls(h[i], (P - 2LL) * f[i] + P - p2(i - 1) + mu[i]);
    L (j, 2, N / i) {
      pls(f[i * j], h[i] + (p2(j / 2 - 1) - 1LL + P) * g[i]);
    }
  }
  L (i, 2, N) {
    qm(f[i] += f[i - 1] - P);
    qm(g[i] += g[i - 1] - P);
    qm(h[i] += h[i - 1] - P);
  }
  for (LL l = 1, r; l <= n; l = r + 1) {
    r = n / (n / l);
    if (n / l <= N) {
      break;
    }
    idx[++tot] = n / l;
  }
  reverse(idx + 1, idx + tot + 1);
  L (i, 1, tot) {
    LL x = idx[i];
    int id = n / x;
    smu[id] = 1;
    for (LL l = 2, r; l <= x; l = r + 1) {
      r = x / (x / l);
      LL len = (r - l + 1) % P;
      pls(smu[id], (P - Mu(x / l)) * len);
      pls(fp[id], H(x / l) * len + G(x / l) * (P - len + W(r) + P - W(l - 1)));
    }
    for (LL l = 1, r; l <= x; l = r + 1) {
      r = x / (x / l);
      pls(hp[id], (3LL * (F(x / l) + p2(x / l - 1)) + P - 2) * (Mu(r) + P - Mu(l - 1)));
    }
    qm(gp[id] = hp[id] * 2 - P);
    int y = ((P - 2LL) * F(x) + P - p2(x) + 1) % P;
    qm(gp[id] += y - P);
    qm(hp[id] += y - P);
  }
}

int main () {
  // FIO("1");
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  init();
  cout << (F(n) + p2(n - 1)) % P << '\n';
  // cerr << clock() << '\n';
}
// I love WHQ!

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 273ms
memory: 47480kb

input:

6

output:

38

result:

ok 1 number(s): "38"

Test #2:

score: 4
Accepted
time: 271ms
memory: 47292kb

input:

7

output:

73

result:

ok 1 number(s): "73"

Test #3:

score: 4
Accepted
time: 277ms
memory: 47304kb

input:

8

output:

148

result:

ok 1 number(s): "148"

Test #4:

score: 4
Accepted
time: 280ms
memory: 47380kb

input:

9

output:

284

result:

ok 1 number(s): "284"

Test #5:

score: 4
Accepted
time: 281ms
memory: 47564kb

input:

10

output:

565

result:

ok 1 number(s): "565"

Subtask #2:

score: 13
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 13
Accepted
time: 271ms
memory: 47296kb

input:

30

output:

536938322

result:

ok 1 number(s): "536938322"

Test #7:

score: 13
Accepted
time: 281ms
memory: 47420kb

input:

35

output:

210046687

result:

ok 1 number(s): "210046687"

Test #8:

score: 13
Accepted
time: 268ms
memory: 47280kb

input:

38

output:

680532913

result:

ok 1 number(s): "680532913"

Test #9:

score: 13
Accepted
time: 276ms
memory: 47544kb

input:

39

output:

362030079

result:

ok 1 number(s): "362030079"

Test #10:

score: 13
Accepted
time: 279ms
memory: 47220kb

input:

40

output:

723529503

result:

ok 1 number(s): "723529503"

Subtask #3:

score: 17
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 17
Accepted
time: 285ms
memory: 47304kb

input:

2000

output:

686289840

result:

ok 1 number(s): "686289840"

Test #12:

score: 17
Accepted
time: 271ms
memory: 47292kb

input:

2500

output:

672176744

result:

ok 1 number(s): "672176744"

Test #13:

score: 17
Accepted
time: 278ms
memory: 47488kb

input:

2998

output:

77001108

result:

ok 1 number(s): "77001108"

Test #14:

score: 17
Accepted
time: 271ms
memory: 47292kb

input:

2999

output:

337824775

result:

ok 1 number(s): "337824775"

Test #15:

score: 17
Accepted
time: 270ms
memory: 47472kb

input:

3000

output:

636156660

result:

ok 1 number(s): "636156660"

Subtask #4:

score: 21
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 21
Accepted
time: 290ms
memory: 47308kb

input:

100000

output:

809175948

result:

ok 1 number(s): "809175948"

Test #17:

score: 21
Accepted
time: 278ms
memory: 47472kb

input:

200000

output:

425311829

result:

ok 1 number(s): "425311829"

Test #18:

score: 21
Accepted
time: 280ms
memory: 47304kb

input:

500000

output:

302623178

result:

ok 1 number(s): "302623178"

Test #19:

score: 21
Accepted
time: 284ms
memory: 47300kb

input:

900000

output:

683174559

result:

ok 1 number(s): "683174559"

Test #20:

score: 21
Accepted
time: 270ms
memory: 47348kb

input:

1000000

output:

126560600

result:

ok 1 number(s): "126560600"

Subtask #5:

score: 0
Wrong Answer

Dependency #4:

100%
Accepted

Test #21:

score: 0
Wrong Answer
time: 276ms
memory: 47512kb

input:

100000000

output:

786411958

result:

wrong answer 1st numbers differ - expected: '269652149', found: '786411958'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%