My issue
TLE error!
Is my approach correct?
My code
#include <stdio.h>
#include <math.h>
int main(void) {
// your code goes here
int T;
scanf("%d\n", &T);
for(int i=0; i<T; i++){
long int A, B;
int count=0;
scanf("%ld %ld", &A, &B);
while(A){
if(A==B){
A=0;
}
else if(A>B){
if(A%2==0){
count++;
A/=2;
}
else{
count++;
A=(A-1)/2;
}
}
else{
if(A%2==0||A==1){
count++;
A*=2;
}
else{
count++;
A=(A-1)/2;
}
}
}
printf("%d\n", count);
}
return 0;
}
Problem Link: COOKMACH Problem - CodeChef