#include <bits/stdc++.h>
using namespace std;

using ll = long long;

ll modpow(ll x, ll y, ll m) {
	if (!y) return 1;
	x %= m; if (y % 2) return modpow(x, y - 1, m) * x % m;
	return modpow(x * x % m, y / 2, m);
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    ll n, p;
    cin >> n >> p;
    ll s = 0;
    while (n > 0) {
        n /= p;
        s += n;
    }
    cout << modpow(p, s, 998244353) << '\n';
    return 0;
}