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 Increment / decrement to make array elements equal
- Minimum number of cuts required to make circle segments equal sized
- Minimum numbers (smaller than or equal to N) with sum S
- Find the number of operations required to make all array elements Equal
- Minimum changes required to make two arrays identical
- Minimum gcd operations to make all array elements one
- Find minimum number of coins that make a given value
- Minimum Operations to make value of all vertices of the tree Zero
- Minimum operations to make GCD of array a multiple of k
- Minimum removals from array to make GCD greater
- Minimum number of changes required to make the given array an AP
- Minimum number of elements to be removed to make XOR maximum
- Minimum Increment operations to make Array unique
- Find minimum operations needed to make an Array beautiful
- Minimum operations required to make all the elements distinct in an array
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.