#include #include using namespace std; using Mint = atcoder::modint998244353; struct Mat { Mint A[3][3]; }; Mat mul(Mat a, Mat b) { Mat c; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) c.A[i][j] += a.A[i][k] * b.A[k][j]; return c; } Mat pow(Mat a, int x) { if (x == 1) return a; auto ret = pow(a, x / 2); ret = mul(ret, ret); if (x & 1) ret = mul(ret, a); return ret; } int main() { int N, K; cin >> N >> K; Mint ans = 0; for (int x = 1; x <= K; x++) { Mat A; A.A[0][0] = K; A.A[0][1] = K - (x - 1); A.A[1][1] = x - 1; A.A[1][2] = K - (x - 1); A.A[2][2] = x - 1; A = pow(A, N); ans += A.A[0][2]; } cout << ans.val() << endl; }