📜  哥德巴赫对奇数的弱猜想

📅  最后修改于: 2021-05-07 10:00:38             🧑  作者: Mango

给定一个奇数N,任务是查找该数字是否可以表示为3个质数的总和。

例子:

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

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

方法:
在数论中,哥德巴赫的弱猜想(也称为奇数哥德巴赫猜想),三元哥德巴赫问题或三素数问题指出,大于5的每个奇数都可以表示为三个素数的总和。 (一个素数可以在相同的总和中多次使用。)。

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
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


Java
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


Python3
# 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()


C#
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


输出:
NO
YES