Under construction

Still being built. Things may change

From A to B

Interview

Time limit1sMemory limit512 MB

Summary
Given two integers a and b, find the minimum number of operations (divide an even number by two, or add one) needed to turn a into b.
Level

Medium5 of 10

Topics
Greedy, Bit manipulation, Math, Implementation
Solved
No attempts yet

Problem

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

  • Divide a by two (only when a is even)
  • Add one to a

What is the minimum number of operations needed to turn a into b?

Input

The first line contains two space-separated integers a and b. (1 ≤ a, b ≤ 10^9)

Output

Print a single integer: the minimum number of the given operations needed to turn a into b.

Examples2

  1. Example 1

    Input
    103 27
    
    Expected output
    4
    
  2. Example 2

    Input
    3 8
    
    Expected output
    5