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:
- Minimum operations to make two numbers equal
- Make all numbers of an array equal
- Minimum deletions required to make GCD of the array equal to 1
- Minimum cost to make all array elements equal
- Minimum steps to make the product of the array equal to 1
- Minimum changes required to make all element in an array equal
- Minimum operations required to make all the array elements equal
- Minimum value of X to make all array elements equal by either decreasing or increasing by X
- Minimum Increment / decrement to make array elements equal
- Find the minimum number of preprocess moves required to make two strings equal
- Minimum decrement operations to make Array elements equal by only decreasing K each time
- Minimum number of cuts required to make circle segments equal sized
- Find the minimum number of operations required to make all array elements equal
- Minimum numbers (smaller than or equal to N) with sum S
- Remove two consecutive integers from 1 to N to make sum equal to S
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.