Related Articles

Related Articles

Goldbach’s Weak Conjecture for Odd numbers
  • Difficulty Level : Easy
  • Last Updated : 23 Dec, 2019

Given an odd number N, the task is to find if the number can be represented as the sum of 3 prime numbers.

Examples:

Input: N = 7
Output: Yes
Explanation:
2 + 2 + 3 = 7

Input: N = 17
Output: Yes
Explanation:
2 + 2 + 13 = 17

Approach:
In number theory, Goldbach’s weak conjecture, also known as the odd Goldbach conjecture, the ternary Goldbach problem, or the 3-primes problem, states that Every odd number greater than 5 can be expressed as the sum of three primes. (A prime may be used more than once in the same sum.).

Below is the implementation of the above approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
  
// if a number can 
// be represent as 
// as a sum of 3 prime
void check(int n) 
{
    if (n % 2 == 1 && n > 5) 
        cout << "Yes\n";
    else
        cout << "No\n";
}
      
// Driver code
int main()
{
    int a = 3;
    int b = 7;
    check(a);
    check(b);
    return 0;
}
  
// This code is conributed by 29AjayKumar

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

class GFG 
{
    // Function to check 
    // if a number can 
    // be represent as 
    // as a sum of 3 prime
  
    static void check(int n) 
    {
        if (n % 2 == 1 && n > 5
        {
            System.out.println("YES");
        
        else 
        {
            System.out.println("NO");
        }
    }
      
    // Driver code
    public static void main(String[] args) 
    {
        int a = 3;
        int b = 7;
        check(a);
        check(b);
    }
  
// This code is contributed by PrinciRaj1992

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Function to check 
# if a number can 
# be represent as 
# as a sum of 3 prime
def check(n):
  if n % 2 == 1 and n > 5:
    print('YES')
  else:
    print('NO')
  
# Driver code
def main():
  a = 3
  b = 7
  check(a)
  check(b)
  
main()

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

using System;
  
class GFG 
{
    // Function to check 
    // if a number can 
    // be represent as 
    // as a sum of 3 prime
    static void check(int n) 
    {
        if (n % 2 == 1 && n > 5) 
        {
            Console.WriteLine("YES");
        
        else
        {
            Console.WriteLine("NO");
        }
    }
      
    // Driver code
    public static void Main(String[] args) 
    {
        int a = 3;
        int b = 7;
        check(a);
        check(b);
    }
  
// This code is contributed by PrinciRaj1992

chevron_right


Output:

NO
YES

competitive-programming-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :