from copy import deepcopy MOD = 998244353 n, K = map(int, input().split()) def f(i, j, k): i %= K j %= K k %= K return (i * K + j) * K + k k3 = K ** 3 A = [[0] * k3 for _ in range(k3)] for i in range(K): for j in range(K): for k in range(K): A[f(i, j, j + k)][f(i, j, k)] += 1 A[f(i, i + j, k)][f(i, j, k)] += 1 A[f(i + 1, j, k)][f(i, j, k)] += 1 B = [0] * k3 B[0] = 1 while n: if n & 1: C = [0] * k3 for i in range(k3): for j in range(k3): C[i] += A[i][j] * B[j] C[i] %= MOD B = C[:] n >>= 1 C = [[0] * k3 for _ in range(k3)] for i in range(k3): for j in range(k3): for k in range(k3): C[i][j] += A[i][k] * A[k][j] C[i][j] %= MOD A = deepcopy(C) ans = 0 for i in range(K): for j in range(K): ans += B[f(i, j, 0)] ans %= MOD print(ans)