Problem C
From A to B

You are given two integers, $a$ and $b$. You want to transform $a$ to $b$ by performing a sequence of operations. You can only perform the following operations:

  • Divide $a$ by two (only if $a$ is even)

  • Add one to $a$

What is the minimum number of these operations you need to transform $a$ into $b$?


The single line of input contains two space-separated integers $a$ and $b$ ($1\le a,b \le 10^9$). You want to transform $a$ into $b$ using only the operations given above.


Output a single integer, which is the minimum number of the given operations needed to transform $a$ into $b$.

Sample Input 1 Sample Output 1
103 27
Sample Input 2 Sample Output 2
3 8
CPU Time limit 1 second
Memory limit 1024 MB
Statistics Show
License Creative Commons License (cc by-sa)

Please log in to submit a solution to this problem

Log in