#include #if __has_include() #include using namespace atcoder; #endif using namespace std; using ll = long long; using mint = modint998244353; int main() { ll n; int p; cin >> n >> p; ll k = 0; while (n) { k += n/p; n /= p; } cout << mint(p).pow(k).val() << '\n'; return 0; }