My issue
I am getting the right output but time limit gets exceeded, what can i do to optimize it,
My code
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int a,b,k;
cin >> a >> b >> k;
int c=0;
while(b!=a)
{
c++;
if(((b/k)>=a) && ((b%k)==0))
{
b=b/k;
}
else
{
b=b-1;
}
}
cout << c << endl;
}
int main() {
int t;
cin >> t;
while(t--)
{
solve();
}
}
Problem Link: Change A to B Practice Coding Problem