def mul(A, B) : N=len(A) mod=998244353 C=[[0 for i in range(N)] for j in range(N)] for i in range (N) : for j in range(N) : for k in range(N) : C[i][j]+=A[i][k]*B[k][j]%mod C[i][j]%=mod return C def powmat(A, n) : N=len(A) C=[[0 for i in range(N)] for j in range(N)] for i in range(N) : C[i][i] = 1 while n > 0 : if n%2==1 : C = mul(C,A) A=mul(A,A) n>>=1 return C def solve() : N, K = map(int,input().split()) mod = 998244353 M = K**3 A = [[0 for i in range(M)] for j in range(M)] for i in range(K) : for j in range(K) : for k in range(K) : cur=i*K*K+j*K+k; nxt1=i*K*K+j*K+(k+1)%K; nxt2=i*K*K+(j+k)%K*K+k; nxt3=(i+j)%K*K*K+j*K+k; A[nxt1][cur]+=1 A[nxt2][cur]+=1 A[nxt3][cur]+=1 C = powmat(A, N) ans = 0 for i in range(K*K) : ans += C[0][i] print(ans%mod) solve()