QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#175816 | #6417. Classical Summation Problem | danielkou5855 | WA | 1ms | 3592kb | C++17 | 1.3kb | 2023-09-11 00:45:10 | 2023-09-11 00:45:12 |
Judging History
answer
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 998244353;
ll exp(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
vector<ll> factorial;
void generate_factorial(int m) {
factorial.resize(m + 1);
factorial[0] = 1;
for (ll i = 1; i <= m; i++) {
factorial[i] = factorial[i - 1] * i; factorial[i] += MOD; factorial[i] %= MOD;
}
}
ll choose(ll a, ll b) {
ll tmp = factorial[a];
tmp *= exp(factorial[a - b], MOD - 2); tmp += MOD; tmp %= MOD;
tmp *= exp(factorial[b], MOD - 2); tmp += MOD; tmp %= MOD;
return tmp;
}
signed main() {
int N, K; cin >> N >> K;
generate_factorial(max(N + 1, K));
if (K % 2 == 1) {
ll ans = ((N + 1) / 2) * exp(N, K) % MOD;
cout << ans << "\n";
return 0;
}
ll ans = 0;
for (int i = 1; i < N; i++) {
ll tmp = choose(K, K / 2) * exp(i, K / 2) % MOD;
tmp = tmp * exp(N - i, K / 2) % MOD;
ans += tmp; ans %= MOD;
}
ll tmp2 = (N + 1) * exp(N, K) % MOD;
tmp2 -= ans; tmp2 += MOD; tmp2 %= MOD;
tmp2 *= exp(2, MOD - 2); tmp2 %= MOD;
cout << tmp2 << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3376kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3432kb
input:
10 9
output:
8778235
result:
wrong answer 1st numbers differ - expected: '508778235', found: '8778235'