Goldbach’s Weak Conjecture for Odd numbers
Last Updated :
01 Nov, 2023
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++
#include <bits/stdc++.h>
using namespace std;
void check( int n)
{
if (n % 2 == 1 && n > 5)
cout << "Yes\n" ;
else
cout << "No\n" ;
}
int main()
{
int a = 3;
int b = 7;
check(a);
check(b);
return 0;
}
|
Java
class GFG
{
static void check( int n)
{
if (n % 2 == 1 && n > 5 )
{
System.out.println( "YES" );
}
else
{
System.out.println( "NO" );
}
}
public static void main(String[] args)
{
int a = 3 ;
int b = 7 ;
check(a);
check(b);
}
}
|
Python3
def check(n):
if n % 2 = = 1 and n > 5 :
print ( 'YES' )
else :
print ( 'NO' )
def main():
a = 3
b = 7
check(a)
check(b)
main()
|
C#
using System;
class GFG
{
static void check( int n)
{
if (n % 2 == 1 && n > 5)
{
Console.Write( "YES" );
}
else
{
Console.WriteLine( "NO" );
}
}
public static void Main(String[] args)
{
int a = 3;
int b = 7;
check(a);
check(b);
}
}
|
Javascript
function check(n)
{
if (n % 2 == 1 && n > 5)
{
document.write( "YES" );
}
else
{
document.write( "NO" + "<br>" );
}
}
var a = 3;
var b = 7;
check(a);
check(b);
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...