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 operations required to make all the array elements equal
- Minimum Increment / decrement to make array elements equal
- Find the minimum number of preprocess moves required to make two strings equal
- Minimum number of cuts required to make circle segments equal sized
- 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
- Minimum removals to make array sum odd
- Minimum cost to make two strings same
- Minimum removals from array to make GCD greater
- Minimum operations to make GCD of array a multiple of k
- Minimum changes required to make two arrays identical
- Find minimum number of coins that make a given value
- Minimum number of changes required to make the given array an AP
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.