QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#472067#6417. Classical Summation ProblemUESTC_OldEastWest#WA 9ms18660kbC++171.3kb2024-07-11 14:15:012024-07-11 14:15:01

Judging History

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

  • [2024-07-11 14:15:01]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:18660kb
  • [2024-07-11 14:15:01]
  • 提交

answer

#include <bits/stdc++.h>
using ll = long long;
#define int ll
const int N = 1e6 + 5;
const int MOD = 998244353;

std::vector<int> fac, inv;

int QSM (int x, int p) {
  int ans = 1;
  while (p) {
    if (p & 1) ans = 1ll * ans * x % MOD;
    p >>= 1, x = 1ll * x * x % MOD;
  }
  return ans;
}

void Prep() {
  fac = std::vector<int> (N, 1);
  inv = std::vector<int> (N, 1);
  for (int i = 1; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
  inv[N - 1] = QSM(fac[N - 1], MOD - 2);
  for (int i = N - 2; i >= 1; --i) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
}

int C (int n, int m) {
  if (n < m) return 0;
  else return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

void charming() {
  int n, k; std::cin >> n >> k;
  int ans = 0;
  if (k & 1) {
    ans = 1ll * (n + 1) * QSM(2, MOD - 2) % MOD * QSM(n, k) % MOD;
    std::cout << ans << '\n';
    return;
  }
  int cnt = 0;
  for (int i = 1, ncnt; i <= n / 2; ++i) {
    ncnt = 1ll * C(k, k / 2) * (C(k / 2 + i - 1, k / 2) - C(k / 2 + i - 2, k / 2)) % MOD;
    cnt = (cnt + ncnt) % MOD;
    // ans = (ans + 1ll * ncnt * i % MOD) % MOD;
  }
  ans = (ans + 1ll * (n + 1) * QSM(2, MOD - 2) % MOD * (QSM(n, k) - cnt) % MOD) % MOD;
  ans = (ans + MOD) % MOD;
  std::cout << ans << '\n';
}

signed main() {
  Prep();
  charming();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 18660kb

input:

3 2

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 9ms
memory: 18660kb

input:

5 3

output:

375

result:

ok 1 number(s): "375"

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 18620kb

input:

2 2

output:

3

result:

wrong answer 1st numbers differ - expected: '5', found: '3'