#include #include using namespace std; int n, k, s; constexpr int M = 998244353; inline int index(int x, int y, int z) { return x + k * (y + k * z); } void mmul(long long *X, const long long *A, const long long *B) { static long long *tmp = nullptr; if (tmp == nullptr) tmp = new long long[s*s]; for (int i = 0; i < s; i++) for (int j = 0; j < s; j++) { long long sum = 0; for (int k = 0; k < s; k++) sum += A[i*s+k] * B[k*s+j] % M; tmp[i*s+j] = sum % M; } memcpy(X, tmp, sizeof(*X)*s*s); } void mpow(long long *A, int k) { static long long *tmp = nullptr, *P = nullptr; if (tmp == nullptr) tmp = new long long[s*s]; if (P == nullptr) P = new long long[s*s]; for (int i = 0; i < s; i++) for (int j = 0; j < s; j++) tmp[s*i + j] = (i==j), P[s*i+j] = A[s*i+j]; while (k > 0) { if (k % 2) mmul(tmp, tmp, P); mmul(P, P, P); k /= 2; } memcpy(A, tmp, sizeof(*A)*s*s); } int main() { cin >> n >> k; s = k*k*k; long long A[s][s]; memset(A, 0, sizeof A); for (int x = 0; x < k; x++) for (int y = 0; y < k; y++) for (int z = 0; z < k; z++) { int i = index(x, y, z); A[index((x+1)%k, y, z)][i]++; A[index(x, (y+x)%k, z)][i]++; A[index(x, y, (z+y)%k)][i]++; } mpow(&A[0][0], n); long long ans = 0; for (int x = 0; x < k; x++) for (int y = 0; y < k; y++) ans += A[index(x, y, 0)][0] % M; cout << ans%M << endl; }