#include using namespace std; using ll = long long; constexpr int MOD = 998244353; int main() { int N, M; cin >> N >> M; vector D(N + 10, 0); for (int i = 2; i <= M; i++) { for (int k = 1; k * i <= N; k++) { D[k * i - 1]++; } } vector pw(N + 10); pw[0] = 0, pw[1] = 1, pw[2] = M - 2; for (int i = 2; i < N; i++) { pw[i + 1] = (M - 1) * pw[i] % MOD; } for (int i = 0; i <= N; i++) { pw[i] = (pw[i] == 0 ? 0 : MOD - pw[i]); } vector dp(N + 10, 0); vector dp2(N + 10); dp2[0] = 1; for (int i = 0; i < N; i++) { dp2[i + 1] = (M - 1) * dp2[i] % MOD; } for (int i = 0; i <= N; i++) { for (int j = 0; j < i; j++) { dp[i] += dp2[j] * D[i - j]; dp[i] %= MOD; } for (int j = 0; j < i; j++) { dp2[i] += dp[j] * pw[i - j]; dp2[i] %= MOD; } } ll all = 1; for (int i = 0; i < N; i++) { all *= M; all %= MOD; } ll ans = (all + MOD - dp2[N]) % MOD; cout << ans << endl; }