#include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=998244353; ll mod_pow(ll x,ll y,ll mod){ ll res=1; while(y>0){ if(y&1){ res*=x; res%=mod; } x*=x; x%=mod; y/=2; } return res; } int main(){ ll n,p; cin>>n>>p; ll cnt=0; while(n>0){ cnt+=n/p; n/=p; } ll ans=mod_pow(p,cnt,MOD); cout<