QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472067 | #6417. Classical Summation Problem | UESTC_OldEastWest# | WA | 9ms | 18660kb | C++17 | 1.3kb | 2024-07-11 14:15:01 | 2024-07-11 14:15:01 |
Judging History
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'