Given a positive integer . The task is to represent it as a sum of the maximum possible number of prime numbers. (N > 1)
Input : N = 5 Output : 2 3 Input : N = 6 Output : 2 2 2
At first, the problem might seem to involve some use of Goldbach’s conjecture. But the key observation here is to maximise the number of terms used, you should use as small numbers as possible. This leads to the following idea:
- If N is even, it can be represented as sum of two’s.
- Otherwise, has to be even and hence N can be represented as sum of one 3 and two’s.
This is the maximum number of primes whose sum is N.
Below is the implementation of the above approach:
Time Complexity: O(N)
- Number which has the maximum number of distinct prime factors in the range M to N
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Print the nearest prime number formed by adding prime numbers to N
- Check if a prime number can be expressed as sum of two Prime Numbers
- Find prime number K in an array such that (A[i] % K) is maximum
- Express an odd number as sum of prime numbers
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Sum of Maximum and Minimum prime factor of every number in the Array
- Find all the prime numbers of given number of digits
- Check if a number can be written as a sum of 'k' prime numbers
- New Algorithm to Generate Prime Numbers from 1 to Nth Number
- Find a sequence of N prime numbers whose sum is a composite number
- Sum of all the prime numbers with the maximum position of set bit ≤ D
- Minimum and Maximum prime numbers in an array
- Maximum no. of contiguous Prime Numbers 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 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.