#include using namespace std; int get_ceil(long long m,long long tmp){ int ans=1; int cur=tmp; while(cur>n>>m>>p; long long tmp; long long min_a=-1; for(int i=0;i>tmp; if (tmp>m){ min_a=1; }else{ long long cnt=0; while(tmp%p==0){ cnt++; tmp/=p; } if (tmp==1) continue; int ttt=get_ceil(m,tmp); if(min_a==-1){ min_a=ttt+cnt*(ttt-1); }else{ min_a=min(min_a,ttt+cnt*(ttt-1)); } } } cout<