Minimum Number of Operations to Make X and Y Equal
You are given two positive integers x and y.
In one operation, you can do one of the four following operations:
- Divide
xby11ifxis a multiple of11. - Divide
xby5ifxis a multiple of5. - Decrement
xby1. - Increment
xby1.
Return the minimum number of operations required to make x and y equal.
Example 1
Input
x = 26, y = 1Output
3By decrementing 26 to 25, then dividing by 5 twice, 26 becomes 1 in 3 operations, which is the minimum.
Example 2
Input
x = 54, y = 2Output
4By incrementing 54 to 55, dividing by 11, dividing by 5, and incrementing once, 54 becomes 2 in 4 operations, which is the minimum.
Constraints
- 1 <= x, y <= 10^4