#include #include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; vector get(vector &a, int l, int r) { return {a.begin() + l, a.begin() + r}; } int main(void) { int n, m; cin >> n >> m; vector ok(n + 1), ng(n + 1), a(n + 1), b(n + 1); for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n / i; ++j) { a[i * j] += 1; } } for (int i = 1; i <= n; ++i) { b[i] = mint(m - 1) * mint(m).pow(i - 1); } for (int i = 0; i <= n; ++i) { ok[i] = mint(m).pow(i); } auto dc = [&](auto self, int l, int r) { if (l + 1 == r) { ok[l] -= ng[l]; return; } int m = (l + r) / 2; self(self, l, m); int n = r - l; auto x = convolution(get(ok, l, m), get(a, 0, n)); auto y = convolution(get(ng, l, m), get(b, 0, n)); for (int i = m; i < r; ++i) { ok[i] -= y[i - m + n / 2]; ng[i] += x[i - m + n / 2]; } self(self, m, r); }; dc(dc, 0, n + 1); mint ans = mint(m).pow(n) - ok[n]; cout << ans.val() << endl; return 0; }