#P8093. Cow Soulmate Transformation

    ID: 21276 Type: Default 1000ms 256MiB

Cow Soulmate Transformation

Cow Soulmate Transformation

Farmer John’s cows each have a personality represented by an integer \(p_i\) (with \(1 \le p_i \le 10^{18}\)). Two cows are soulmates if they share the exact same personality value. In each pair, only the first cow is allowed to perform a series of operations to match the personality value of the second cow. The permitted operations are as follows:

  • Multiply the personality by 2: \(x \to 2x\).
  • Divide the personality by 2 (only when it is even): \(x \to \frac{x}{2}\).
  • Add 1 to the personality: \(x \to x+1\).

Given an initial personality \(p_1\) for the first cow and a target personality \(p_2\) for the second cow, determine the minimum number of operations required for the first cow to transform her personality into \(p_2\), thereby making the pair soulmates.

Note: It is guaranteed that \(1 \le p_1, p_2 \le 10^{18}\).

inputFormat

The input consists of a single line with two space‐separated integers \(p_1\) and \(p_2\), representing the personality values of the first and second cow respectively.

outputFormat

Output a single integer, the minimum number of operations required for the first cow to transform her personality into \(p_2\).

sample

3 10
4