P11560 [MX-X7-T1] [LSOT-3] Dividing Cake.

Background

Original problem link: . There used to be a rather bizarre background story hinting at modern marketing accounts, but it was deleted because it was too bizarre.

Description

Given two positive integers $a$ and $b$, you may choose one of the following operations each time: 1. $a\gets a\times 2$. 2. $b\gets b-1$. 3. $b\gets b+1$. Find the minimum number of operations needed to make $a=b$.

Input Format

Only one line with two positive integers $a,b$.

Output Format

Only one line with one non-negative integer, representing the minimum number of operations.

Explanation/Hint

**Sample Explanation #1** Initially, $a=1$ and $b=5$. - Perform operation $1$, resulting in $a=2$, $b=5$. - Perform operation $1$, resulting in $a=4$, $b=5$. - Perform operation $2$, resulting in $a=4$, $b=4$. The total number of operations is $3$. It can be proven that there is no solution with fewer operations. **Constraints** For $28\%$ of the testdata, $a,b\le 20$. For $60\%$ of the testdata, $a,b\le 5000$. For all testdata, $1\le a,b\le 10^9$. Translated by ChatGPT 5