All problems

Problem 475

Broken Calculator

Medium · 20 pts · Math, Greedy

Problem

A broken calculator shows the number X and has only two working buttons: 'double', which multiplies the displayed number by 2, and 'decrement', which subtracts 1. Find the minimum number of button presses to display Y. Working backwards from Y is easier: if Y is even, the last press was probably a double, so halve it; if Y is odd, add one; once Y is at most X, only decrements remain.

Input

Two integers X and Y.

Output

Print the minimum number of operations.

Constraints

1 <= X, Y <= 1000000000

Example input

2 3

Example output

2

Explanation

From 2 to 3: double to get 4, then decrement to get 3. That takes 2 operations.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Monotone Increasing Digits Next: Bag of Tokens