N, k = list(map(int, input().split())) mod = 998244353 mat_len = k ** 3 def mul(A, B) : C = [[0 for _ in range(mat_len)] for _ in range(mat_len)] for i in range (mat_len): for j in range(mat_len): for k in range(mat_len): C[i][j]+=A[i][k]*B[k][j]%mod C[i][j]%=mod return C B = [[0] * mat_len for _ in range(mat_len)] 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 = [[0] * mat_len for _ in range(mat_len)] for i in range(mat_len): ans[i][i] = 1 while N: if N & 1: ans = mul(ans, B) B=mul(B, B) N>>=1 ret = 0 for i in range(k**2): ret = (ret + ans[i][0])%mod print(int(ret))