update logic

This commit is contained in:
ShazidMahsrafi 2024-06-26 14:50:42 +06:00
parent 6e7cd9a3a2
commit ca14f7d824

View File

@ -26,19 +26,14 @@ void solve()
{ {
int x,y,k; int x,y,k;
cin>>x>>y>>k; cin>>x>>y>>k;
while(k) while(k && x>1)
{ {
int r=x%y; int r=y-x%y;
x += min(k,y-r); x += min(k,r);
k -= min(k,y-r); k -= min(k,r);
while(x%y==0) x /= y; while(x%y==0) x /= y;
if(x==1)
{
cout<<k%(y-1)+1<<endl;
return;
}
} }
cout<<x<<endl; cout<<x+k%(y-1)<<endl;
} }
signed main() signed main()