Problems > Broken Calculator

Broken Calculator

Difficulty: 1800 4000 ms 128 MB

math greedy

A calculator supports two buttons: DOUBLE (x → 2x) and DECREMENT (x → x−1). Print the minimum presses to turn A into B.

Input: one line with two integers A and B.

Output: the minimum number of button presses.

Constraints:

  • 1 ≤ A, B ≤ 1018

Sample Tests

Input 1
2 3
Output 1
2
Input 2
5 8
Output 2
2

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.