#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MEM(a,b) memset((a),(b),sizeof(a)) const LL INF = 1e9 + 7; const int N = 1e3 + 10; const LL mod = 998244353; LL powmod(LL a, LL b) { LL ans = 1; while (b) { if (b & 1) ans = ans * a % mod; b >>= 1; a = a * a % mod; } return ans; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); LL n, p; cin >> n >> p; LL cnt = 0; while (n) cnt += n / p, n /= p; cout << powmod(p, cnt) << endl; return 0; }