Given a positive integer N > 1. Find the maximum count of prime numbers whose sum is equal to given N.
Input : N = 5
Output : 2
Explanation : 2 and 3 are two prime numbers whose sum is 5.
Input : N = 6
Explanation : 2, 2, 2 are three prime numbers whose sum is 6.
For maximum number of primes whose sum is equal to given n, prime numbers must be as small as possible. So, 2 is smallest possible prime number and is an even number. Next prime number greater than 2 is 3 which is odd. So, for any given n there are two conditions, either n will be odd or even.
- Case 1 : n is even, In this case n/2 will be the answer (n/2 number of 2 will result into sum of n).
- Case 1 : n is odd, In this case floor(n/2) will be the answer ((n-3)/2 number of 2 and one 3 will result into sum of n.
Below is the implementation of the above approach:
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.