#include #include using namespace std; using ll = long long; #define REP(i,n) for(int i=0;i void chmin(T& a, T b) { a = min(a, b); } template void chmax(T& a, T b) { a = max(a, b); } #define PR(x) cerr << #x << "=" << x << endl using i128 = __int128_t; int main() { ll n, p; cin >> n >> p; mint ans = p; ll cnt = 0; ll np = p; while(n >= np) { cnt += n / np; np *= p; } ans = ans.pow(cnt); cout << ans.val(); return 0; }