QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480261#8761. 另一个计数问题HiraethsoulWA 99ms12592kbC++203.7kb2024-07-16 11:52:592024-07-16 11:52:59

Judging History

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

  • [2024-07-16 11:52:59]
  • 评测
  • 测评结果:WA
  • 用时:99ms
  • 内存:12592kb
  • [2024-07-16 11:52:59]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

const int p = 998244353;
const int inv2 = 499122177;
const int inv4 = 748683265;
const int inv6 = 166374059;

struct Min25 // 传入一个n  先求g函数 再求s函数
{
  int n, cur;
  int cnt = 0;
  std::vector<int> id1, id2, w;
  std::vector<int> g1, g2; // 两个前缀和
  std::vector<int> a, vis, s, t;
  int get_id(int val)
  {
    return (val <= cur ? id1[val] : id2[n / val]);
  } // 注意w要开2*cur的空间 因为整除分块最多有2*sqrt(n)种取值
  Min25(int n) : n(n), cur(sqrt(n)), w(2 * cur + 10), g1(2 * cur + 10), g2(2 * cur + 10), a(cur + 10), vis(cur + 10, 0), s(cur + 10), t(cur + 10), id1(cur + 10), id2(cur + 10)
  {
    s[0] = t[0] = 0;
    vis[0] = vis[1] = true;
    for (int i = 2; i <= cur; ++i)
    {
      if (!vis[i])
      {
        a[++cnt] = i;
        s[cnt] += (s[cnt - 1] + i * i % p) % p;
        t[cnt] += (t[cnt - 1] + i) % p;
      }
      for (int j = 1; j <= cnt and i * a[j] <= cur; ++j)
      {
        vis[i * a[j]] = true;
        if (i % a[j] == 0)
        {
          break;
        }
      }
    } // 欧拉筛预处理前缀和
    int tot = 0;
    for (int i = 1, j; i <= n; i = j + 1) // 整除分块预处理id和g(0,m)
    {
      j = n / (n / i);
      int val = n / i;
      w[++tot] = val;
      if (val <= cur)
      {
        id1[val] = tot;
      }
      else
      {
        id2[n / val] = tot;
      }
      val %= p;
      // 求g(0,m)实际上是前缀和但是要去掉1
      g1[tot] = (val * (val + 1) / 2 % p - 1 + p) % p;
      g2[tot] = ((val * (val + 1) % p * (2ll * val + 1) % p * inv6 % p) % p - 1 + p) % p;
    }

    for (int j = 1; j <= cnt; ++j) // dp出g[j][id]
    {
      for (int i = 1; i <= tot and a[j] * a[j] <= w[i]; ++i)
      {
        int k = get_id(w[i] / a[j]);
        g1[i] = (g1[i] - a[j] * (g1[k] - t[j - 1] + p) % p + p) % p;
        g2[i] = (g2[i] - a[j] * a[j] % p * (g2[k] - s[j - 1] + p) % p + p) % p;
      }
    }
  }
  int getprimepres1(int n) // 质数处的函数值的前缀和
  {
    int k = get_id(n);
    return g1[k];
  }
  int getprimepres2(int n) // 质数处的函数值的前缀和
  {
    int k = get_id(n);
    return g2[k];
  }
  int getS(int x, int y)
  {
    if (x < a[y] or x <= 1)
    {
      return 0;
    }
    int k = get_id(x);
    int res = ((g2[k] - g1[k] + p) % p - (s[y - 1] - t[y - 1] + p) % p + p) % p;
    for (int i = y; i <= cnt and a[i] * a[i] <= x; ++i)
    {
      int t1 = a[i], t2 = a[i] * a[i];
      for (int j = 1; t2 <= x; ++j, t1 = t2, t2 = t2 * a[i])
      {
        int tt1 = t1 % p, tt2 = t2 % p;
        res = (res + getS(x / t1, i + 1) * tt1 % p * (tt1 - 1) % p + tt2 * (tt2 - 1) % p) % p;
      }
    }
    return res;
  }
  int getpre(int n) // 前缀和
  {
    return (getS(n, 1) + 1) % p;
  }
};

signed main()
{
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int n;
  std::cin >> n;
  int cur = n % p;
  int ans = (((cur * cur % p * (cur + 1) % p * (cur - 2 + p) % p) * inv2 % p - ((cur * cur % p * (cur - 1 + p) % p * (cur - 1 + p) % p) * inv4 % p - 1 + p) % p) + cur * (cur + 1) % p * (cur - 2 + p) % p * inv2 % p - ((cur * (cur - 1 + p) % p * (2 * cur % p - 1 + p) % p) * inv6 % p - 1 + p) % p + 4 * p) % p;
  ans = ans * inv2 % p;
  cur = n / 2;
  Min25 calc(n);
  Min25 calc1(cur);
  int sum1 = calc.getprimepres1(n) - calc1.getprimepres1(cur); // 质数和
  int sum2 = calc.getprimepres2(n) - calc1.getprimepres2(cur); // 质数平方和

  int res = ((n * (n + 1) / 2 % p - 1 + p) % p * sum1 % p - sum2 - (sum1 * sum1 % p - sum2 + p) % p * inv2 % p % p + p) % p;

  ans = (ans - res + p) % p;
  ans = (ans + p) % p;

  std::cout << ans << '\n';
}

详细

Test #1:

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

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

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

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

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

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

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

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

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

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

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

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

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

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

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

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

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

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

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

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

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

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

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

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

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

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

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

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

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

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: 0
Accepted
time: 41ms
memory: 8320kb

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

score: 0
Accepted
time: 42ms
memory: 8332kb

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

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

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

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

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

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

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 41ms
memory: 8148kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

score: 0
Accepted
time: 38ms
memory: 8188kb

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

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

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: -100
Wrong Answer
time: 99ms
memory: 12592kb

input:

3550627266

output:

467271268

result:

wrong answer 1st numbers differ - expected: '318019384', found: '467271268'