Board Games

View as PDF

Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 256M

Problem types

Soupy boy is playing a game! He is currently on the N^{th} square, and wants to get to the M^{th} square exactly. However, moves in this game are a bit different than your average board game.

Starting from the current square, he can do one of 4 things.

  • Go to the (3 \times N)^{th} square.
  • Go to the (N-1)^{th} square.
  • Go to the (N-3)^{th} square.
  • Go to the (\dfrac{N}{2})^{th} square if the current square is even.

Can you tell soupy boy what is the minimum amount of moves so that he can get to the M^{th} square?

Note: You can assume that soupy boy will not go to a square that is larger than 10^7.

Input Specification

The first and only line of input contains the two integers N and M (1 \le N, M \le 10^5), separated by a space.

Output Specification

Output the minimum amount of moves it takes soupy boy to get to the M^{th} square, starting from the N^{th} square using the moves described above.

Sample Input 1

4 6

Sample Output 1


Sample Input 2

10 1

Sample Output 2



There are no comments at the moment.