QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472144 | #6417. Classical Summation Problem | UESTC_OldEastWest# | RE | 0ms | 0kb | C++20 | 1.1kb | 2024-07-11 14:43:16 | 2024-07-11 14:43:19 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M = 1e5+5;
const int mod = 998244353;
inline int ksm(int x, int p) {
if (p == 0) return 1;
if (p == 1) return x;
int t = ksm(x, p >> 1);
if (p & 1) return t * t % mod * x % mod;
return t * t % mod;
}
inline int inv(int x) {
return ksm(x % mod, mod - 2);
}
int fac[M];
inline int pre() {
fac[0] = 1;
for (int i = 1; i < M; i++) fac[i] = fac[i - 1] * i % mod;
}
inline int C(int n, int m) {
if (n < m) return 0;
return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, k;
pre(); cin >> n >> k;
int ans = (n + 1) * ksm(n, k) % mod * inv(2) % mod;
if (k & 1) return cout << ans << endl, 0;
int res = 0;
for (int i = 1; i <= n - 1; i++) (res += ksm(i, k / 2) * ksm(n - i, k / 2) % mod) %= mod;
res = res * C(k, k / 2) % mod;
ans = ((ans - res * inv(2) % mod) % mod + mod) % mod;
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 2