QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472073 | #6417. Classical Summation Problem | UESTC_OldEastWest# | WA | 13ms | 18828kb | C++17 | 1.4kb | 2024-07-11 14:18:46 | 2024-07-11 14:18:46 |
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;
ncnt = 1ll * ncnt * C(n - i + k / 2 - 1, 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 18660kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 12ms
memory: 18664kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 13ms
memory: 18656kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 10ms
memory: 18696kb
input:
10 9
output:
508778235
result:
ok 1 number(s): "508778235"
Test #5:
score: 0
Accepted
time: 10ms
memory: 18660kb
input:
69 3
output:
11497815
result:
ok 1 number(s): "11497815"
Test #6:
score: 0
Accepted
time: 9ms
memory: 18828kb
input:
994 515
output:
33689623
result:
ok 1 number(s): "33689623"
Test #7:
score: -100
Wrong Answer
time: 6ms
memory: 18660kb
input:
4476 6182
output:
996231872
result:
wrong answer 1st numbers differ - expected: '114894183', found: '996231872'