#include using namespace std; #include using namespace atcoder; using mint = modint998244353; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") 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]; } 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]; } for (int i = 0; i <= N; i++) { for (int j = 0; j < i; j++) { dp[i] += dp2[j] * D[i - j]; } for (int j = 0; j < i; j++) { dp2[i] -= dp[j] * pw[i - j]; } } mint ans = ((mint)M).pow(N) - dp2[N]; cout << ans.val() << endl; }