#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vl = vector; using vvi = vector; using vvl = vector; const int INF = 1 << 28; const ll MOD = 998244353; template bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } int main() { ll n, k; cin >> n >> k; ll dp[n + 1][k][k][k]; // n th char, ho, homu, homura; for (int i = 0; i <= n; ++i) { for (int x = 0; x < k; ++x) { for (int y = 0; y < k; ++y) { for (int a = 0; a < k; ++a) { dp[i][x][y][a] = 0; } } } } dp[1][1][0][0] += 1; // ho dp[1][0][0][0] += 1; // mu dp[1][0][0][0] += 1; // ra for (int i = 1; i < n; ++i) { for (int x = 0; x < k; ++x) { for (int y = 0; y < k; ++y) { for (int a = 0; a < k; ++a) { dp[i + 1][(x + 1) % k][y][a] += dp[i][x][y][a]; // ho dp[i + 1][x][(y + x) % k][a] += dp[i][x][y][a]; // mu dp[i + 1][x][y][(a + y) % k] += dp[i][x][y][a]; // ra dp[i + 1][(x + 1) % k][y][a] %= MOD; dp[i + 1][x][(y + x) % k][a] %= MOD; dp[i + 1][x][y][(a + x * y) % k] %= MOD; } } } } ll ret = 0; for (int x = 0; x < k; ++x) { for (int y = 0; y < k; ++y) { ret = (ret + dp[n][x][y][0]) % MOD; } } cout << ret << "\n"; return 0; }