Given two numbers A and B, the task is to find the minimum number of operations required to make A and B equal. In each operation, any number can be divided by either 2, 3 or 7. If it is not possible then print -1.
Input: A = 14, B = 28
Operation 1: A * 2 = 14 * 2 = 28 which is equal to B.
Input: A = 3, B = 5
No matter how many times the operation is performed, A and B will never be equal.
Approach: A and B can be written as A = x * 2a1 * 3a2 * 7a3 and B = y * 2b1 * 3b2 * 7b3 where x and y are not divisible by 2, 3 and 7. Now,
- If x != y then A and B cannot be made equal with the given operation.
- If x = y then the minimum operations required will be |a1 – b1| + |a2 – b2| + |a3 – b3| because both the numbers need to have equal powers of 2, 3 and 7.
Below is the implementation of the above approach:
- Make all numbers of an array equal
- Minimum deletions required to make GCD of the array equal to 1
- Minimum value of X to make all array elements equal by either decreasing or increasing by X
- Minimum operations required to make all the array elements equal
- Minimum Increment / decrement to make array elements equal
- Minimum number of cuts required to make circle segments equal sized
- Find the minimum number of operations required to make all array elements equal
- Find the minimum number of preprocess moves required to make two strings equal
- Minimum numbers (smaller than or equal to N) with sum S
- Make all elements of an array equal with the given operation
- Find the number of operations required to make all array elements Equal
- Append a digit in the end to make the number equal to the length of the remaining string
- Minimum cost to make two strings same
- Minimum removals to make array sum odd
- Find minimum number of coins that make a given value
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.