import numpy as np mod = 998244353 def mul(A, B) : N=len(A) mod=998244353 C=[[0 for _ in range(N)] for _ 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 N, k = list(map(int, input().split())) B = np.zeros((k**3, k**3)) for i in range(k): for j in range(k): for l in range(k): cur = i*k*k+j*k+l B[i*k*k+j*k+(l+1)%k][cur] += 1 B[i*k*k+(j+l)%k*k+l][cur] += 1 B[(i+j)%k*k*k+j*k+l][cur] += 1 ans = np.identity(k**3) while N: if N&1: ans = mul(ans, B) B=mul(B, B) N>>=1 seq = np.array([0] * (k**3)) seq[0] = 1 ret = 0 f_ans = ans@seq for i in range(k**2): ret = (ret + f_ans[i])%mod print(int(ret))