#include using namespace std; typedef long long ll; typedef pair P; #define REP(i,n) for(int i=0;i> N >> P; ll m=0; for(i=1;;i++){ m+=N/P; if(N/P==0) break; N=N/P; } cout << modpow(P,m) << endl; return 0; }