#include using namespace std; using ll = long long; ll mod_exp(ll b, ll e, ll m){ if (e > 0 && b == 0) return 0; ll ans = 1; b %= m; while (e > 0){ if ((e & 1LL)) ans = (ans * b) % m; e = e >> 1LL; b = (b*b) % m; } return ans; } const ll m1 = 998244352; const ll m2 = 998244353; ll Legendre(ll X, ll p){ ll cnt=0, q=p; while(X/q > 0){ cnt += (X/q) % m1; cnt %= m1; if (q <= X/p) q *= p; else break; } return cnt; } int main(){ ll N, P, e; cin >> N >> P; e = Legendre(N, P); cout << mod_exp(P, e, m2) << endl; return 0; }