#include #define rep(i,n,m) for(int i = (n); i <(m); i++) #define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--) using namespace std; using ll = long long; using mat = vector>; const int MOD = 998244353; mat matmul(int n, mat A, mat B) { mat C(n, vector(n, 0)); rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) { C[i][j] += A[i][k] * B[k][j]; C[i][j] %= MOD; } return C; } int main() { int N, K; cin >> N >> K; // initialize matrix int k3 = K * K * K; mat A(k3, vector(k3, 0)); rep(num, 0, k3) { int i, j, k; i = num % K; j = (num / K) % K; k = (num / (K * K)) % K; int num2 = (i + 1) % K + j * K + k * K * K; int num3 = i + ((i + j)%K) * K + k * K * K; int num4 = i + j * K + ((j + k)%K) * K * K; A[num2][num]++; A[num3][num]++; A[num4][num]++; } int n = N; mat An(k3, vector(k3, 0)); rep(i, 0, k3) An[i][i] = 1; while (n) { if (n & 1) { An = matmul(k3, A, An); } A = matmul(k3, A, A); n >>= 1; } ll ans = 0; rep(num, 0, k3) { int i, j, k; i = num % K; j = (num / K) % K; k = (num / (K * K)) % K; if (k % K != 0) continue; ans += An[num][0]; ans %= MOD; cout << An[num][0] << endl; } cout << ans << endl; return 0; }