Given an integer N ≥ 2, you can split the number as a sum of k integers i.e. N = k1 + k2 + … + kn where each kth element is ≥ 2 then the cost of splitting is calculated as maxDiv(k1) + maxDiv(k2) + … + maxDiv(kn) where maxDiv(x) is the maximum divisor of x which is < x.
The task is to split the number in such a way that the cost is minimized, print the minimized cost in the end.
Input: N = 6
6 can be represented as (3 + 3) and the cost will be 1 + 1 = 2.
Input: N = 5
- When n is prime then the cost will be 1 as we don’t have to split n and the greatest divisor of n less than itself will be 1.
- If n is odd and n – 2 is prime then n can be split into (2 + prime) which will cost 1 + 1 = 2.
- If n is even then the cost will be 2 as according to Goldbach’s conjecture, every even number greater than 2 can be expressed as sum of two primes which is proven till 4 * 1018.
- If all of the above conditions are not satisfied then n must be odd now and if 3 is subtracted from n then it will become even which can be expressed as (3 + even) = (3 + prime + prime) which will cost 3.
Below is the implementation of the above approach:
- Minimize the number of replacements to get a string with same number of 'a', 'b' and 'c' in it
- Minimize the number of steps required to reach the end of the array | Set 2
- Split the array into odd number of segments of odd lengths
- Minimum cost to form a number X by adding up powers of 2
- Split the number into N parts such that difference between the smallest and the largest part is minimum
- Number of ways a convex polygon of n+2 sides can split into triangles by connecting vertices
- Prime points (Points that split a number into two primes)
- Split a number into 3 parts such that none of the parts is divisible by 3
- Minimize the value of N by applying the given operations
- Minimize the absolute difference of sum of two subsets
- Minimize the sum of the squares of the sum of elements of each group the array is divided into
- Minimize sum of adjacent difference with removal of one element from array
- Minimize the maximum minimum difference after one removal from array
- Minimize the difference between the maximum and minimum values of the modified array
- Min Cost Path | DP-6
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.