#K75557. Minimum Operations Transformation

    ID: 34445 Type: Default 1000ms 256MiB

Minimum Operations Transformation

Minimum Operations Transformation

You are given two integers \(n\) and \(m\). Your task is to determine the minimum number of operations required to transform \(n\) into \(m\) using only the following two operations:

  • Increment the integer by 1: \(n \leftarrow n + 1\).
  • Multiply the integer by 2: \(n \leftarrow 2n\).

A greedy approach can be applied by working backwards from \(m\) to \(n\). In particular, while \(m > n\), if \(m\) is even, then you can replace \(m\) by \(\frac{m}{2}\); otherwise, adjust \(m\) by adding 1. Once \(m \le n\), the remaining difference \(n - m\) can be filled by performing increment operations.

This method ensures that the total number of operations is minimized.

inputFormat

The input consists of a single line containing two space-separated integers (n) and (m).

outputFormat

Output a single integer representing the minimum number of operations required to transform (n) into (m).## sample

2 3
2

</p>