In a number game, you start with an initial number S and try to transform the current number into a target number T through a sequence of operations.
There are four operations available in the game. Suppose the current number is x:
| Operation | Result | Cost |
|---|---|---|
+3 |
x + 3 |
x + 4 |
-5 |
x - 5 |
x + 5 |
*7 |
x × 7 |
x × 2 |
/2 |
x / 2 |
x × 3 |
The following rules apply:
-5 operation can only be used when x >= 5./2 operation can only be used when x is divisible by 2.0 cannot be used.Each operation changes the current number and incurs the corresponding cost. The cost is calculated based on the current number x before performing the operation.
For example, when the current number is 10:
+3: 10 → 13, Cost = 10 + 4 = 14-5: 10 → 5, Cost = 10 + 5 = 15*7: 10 → 70, Cost = 10 × 2 = 20/2: 10 → 5, Cost = 10 × 3 = 30Your task is to calculate the minimum total cost required to transform the starting number S into the target number T.
Your program MAY use C/C++ standard library headers.
The first line contains two integers S and T where:
S (0 <= S <= 3000000) represents the starting number.T (0 <= T <= 3000000) represents the target number.min total cost < 2^64It is guaranteed that there exists at least one valid sequence of operations that can transform S into T.
Output a single integer representing the minimum total Cost required to transform S into T. Each line of output must be terminated by a newline character ('\n').