#P11560. 【MX-X7-T1】[LSOT-3] 分蛋糕

【MX-X7-T1】[LSOT-3] 分蛋糕

Background

Original problem link: https://oier.team/problems/X7B.

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

Problem Description

Given two positive integers aa and bb, you may choose one of the following operations each time:

  1. aa×2a\gets a\times 2.
  2. bb1b\gets b-1.
  3. bb+1b\gets b+1.

Find the minimum number of operations needed to make a=ba=b.

Input Format

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

Output Format

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

1 5

3

114514 1919810

87590

Hint

Sample Explanation #1

Initially, a=1a=1 and b=5b=5.

  • Perform operation 11, resulting in a=2a=2, b=5b=5.
  • Perform operation 11, resulting in a=4a=4, b=5b=5.
  • Perform operation 22, resulting in a=4a=4, b=4b=4.

The total number of operations is 33. It can be proven that there is no solution with fewer operations.

Constraints

For 28%28\% of the testdata, a,b20a,b\le 20.

For 60%60\% of the testdata, a,b5000a,b\le 5000.

For all testdata, 1a,b1091\le a,b\le 10^9.

Translated by ChatGPT 5