Given two integers n and m, in a single operation n can be multiplied by either 2 or 3. The task is to convert n to m with minimum number of given operation. If it is impossible to convert n to m with the given operation then print -1.
Input: n = 120, m = 51840
120 * 2 * 2 * 2 * 2 * 3 * 3 * 3 = 51840
Input: n = 42, m = 42
No operation required.
Input: n = 48, m = 72
Approach: If m is not divisible by n then print -1 as n cannot be converted to m with the given operation. Else we can check if on dividing, the quotient has only 2 and 3 as prime factors. If yes then the result will be the sum of powers of 2 and 3 else print -1
Below is the implementation of the above approach:
- Minimum number operations required to convert n to m | Set-2
- Minimum splits required to convert a number into prime segments
- Minimum number of adjacent swaps required to convert a permutation to another permutation by given condition
- Minimum number of given operations required to convert a permutation into an identity permutation
- Minimum operations required to convert X to Y by multiplying X with the given co-primes
- Minimum cost required to convert all Subarrays of size K to a single element
- Minimum flips required to convert given string into concatenation of equal substrings of length K
- Minimum possible number with the given operation
- Number of steps required to convert a binary number to one
- Minimum number of distinct powers of 2 required to express a given binary number
- Minimum number of swaps required to make a number divisible by 60
- Minimum number of given powers of 2 required to represent a number
- Minimum number of integers required such that each Segment contains at least one of them
- Minimum number of primes required such that their sum is equal to N
- Minimum number of changes required to make the given array an AP
- Minimum number of palindromes required to express N as a sum | Set 2
- Minimum number of palindromes required to express N as a sum | Set 1
- Minimum number of operations required to reduce N to 0
- Minimum number of operations required to reduce N to 1
- Minimum number of integers required to fill the NxM grid
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.