VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-for-goldbachs-conjecture-two-primes-with-given-sum/

⇱ Program for Goldbach’s Conjecture (Two Primes with given Sum) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program for Goldbach’s Conjecture (Two Primes with given Sum)

Last Updated : 23 Jul, 2025

Goldbach's conjecture is one of the oldest and best-known unsolved problems in the number theory of mathematics. Every even integer greater than 2 can be expressed as the sum of two primes.

Examples:  

Input :  n = 44
Output : 3 + 41 (both are primes)

Input :  n = 56
Output : 3 + 53 (both are primes) 

Approach: 1

  1. Find the prime numbers using Sieve of Sundaram
  2. Check if the entered number is an even number greater than 2 or not, if no return.
  3. If yes, then one by one subtract a prime from N and then check if the difference is also a prime. If yes, then express it as a sum.

Below is the implementation of the above approach: 


Output
2 + 2 = 4
7 + 31 = 38
3 + 97 = 100

Time Complexity: O(n log n)
Auxiliary Space: O(MAX)


A Goldbach number is a positive integer that can be expressed as the sum of two odd primes. Since four is the only even number greater than two that requires the even prime 2 in order to be written as the sum of two primes, another form of the statement of Goldbach's conjecture is that all even integers greater than 4 are Goldbach numbers.
 
 

Comment