Given a positive integer N greater than 1, the task is to find the minimum count of Prime Numbers whose sum is equal to given N.
Input: N = 100
100 can be written as sum of 2 prime numbers 97 and 3.
Input: N = 25
25 can be written as sum of 3 prime numbers 11, 11, and 3.
For the minimum number of primes whose sum is the given number N, Prime Numbers must be as large as possible. Following are the observation for the above problem statement:
- Case 1: If the number is prime, then the minimum primes numbers required to make sum N is 1.
- Case 2: If the number is even, then it can be expressed as a sum of two primes as per the Goldbach’s Conjecture for every even integer greater than 2. Therefore the minimum prime number required to make the sum N is 2.
Case 3: If the number is odd:
- If (N-2) is prime, then the minimum prime number required to make the given sum N is 2.
- Else The minimum prime numbers required to make the given sum N is 3 because:
As N is odd, then (N - 3) is even. Hence As per case 2: The minimum prime number required to make the sum (N-3) is 2. Therefore, The minimum prime number required to make the sum N is 3(2+1).
Below are the steps:
- Check whether the given number N is prime or not, by using the approach discussed in this article. If Yes then print 1.
- Else as per the above Cases print the minimum number of Prime Numbers required to make the given sum N.
Below is the implementation of the above approach:
Time Complexity: O(√N), where N is the given number.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum number of single digit primes required whose sum is equal to N
- Possible values of Q such that, for any value of R, their product is equal to X times their sum
- Count of pairs in a given range with sum of their product and sum equal to their concatenated number
- Count primes that can be expressed as sum of two consecutive primes and 1
- Count of primes below N which can be expressed as the sum of two primes
- Length of largest sub-array having primes strictly greater than non-primes
- Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range
- Count pairs from 1 to N such that their Sum is divisible by their XOR
- Find the pair (a, b) with minimum LCM such that their sum is equal to N
- Minimum operations required to convert X to Y by multiplying X with the given co-primes
- Sort all special primes in their relative positions
- Find the first N integers such that the sum of their digits is equal to 10
- Find any K distinct odd integers such that their sum is equal to N
- Maximum Primes whose sum is equal to given N
- Number of pairs such that their HCF and LCM is equal
- Count of minimum reductions required to get the required sum K
- Find the number of ordered pairs such that a * p + b * q = N, where p and q are primes
- Minimum replacement of pairs by their LCM required to reduce given array to its LCM
- Split N powers of 2 into two subsets such that their difference of sum is minimum
- Split array into two subarrays such that difference of their sum is minimum
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.