ゴシックバッハは6以下の偶数は2つの奇数素数の和であると予想しています。


<pre name="code" class="java">package vc;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Gotbaha {
	
	//  Set       ,                                
	//           ,        ,         
	private static Set<Integer> sushu = new HashSet<Integer>();

	/*
	 *   n     1-n     ,   Set   
	 * 1    ,     ,   2    
	 * 
	 */
	public static void prime(int n) {
		int j = 0;
		for (int i = 2; i <= n; i++) {
			for (j = 2; j * j <= i; j++)
				//    2 n       ,   ,       ;
				// :n=6,i=2,j=2,  j i   ,     , j=3,3*3>2, 2 n     , i   Set   
				if (i % j == 0)
					break;
			if (j * j > i) {
				sushu.add(i);
			}
		}
	}

	/*
	 *              。           :  >=6            
	 */
	public static void gotbaha(int n) {
		prime(n);//   2~n     
		for (Integer i : sushu) {
			for (Integer j : sushu) {
				//  n=          ,
				if (i + j == n) {
					System.out.println(n + "=" + i + "+" + j);
					System.out.println(n+"      ");
				}
			}
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = 1;
		while (x % 2 != 0) {
			x = sc.nextInt();//     ,          ,     。
		}
		gotbaha(x);
	}
}
 
  
 

运行结果是:

6
6=3+3
6      
C++コード:
// gotbaha.cpp :              。
//            6            

#include "stdafx.h"
#include <set>  
#include <hash_set>
#include <iostream>
using namespace std;
//  Set       ,                                  
//           ,        ,           
set<int> sushu;
void prime(int n);
void gotbaha(int n);
int main()
{
	int a=1;
	while (a % 2 != 0 && a <= 6){
		cout << "        6   ,            "<<endl;
		cin >> a;
	}
	
	gotbaha(a);
	system("pause");

	
	//return 0;
}

/*
*   n     1-n     ,   Set   
* 1    ,     ,   2    
*
*/
void prime(int n){
	int j = 0;
	for (int i = 2; i <= n; i++){
		for (j = 2; j*j <= i; j++)
			//    2 n       ,   ,       ;  
			// :n=6,i=2,j=2,  j i   ,     , j=3,3*3>2, 2 n     , i   Set     
			if (i%j == 0)
				break;
		if (j*j > i)
			sushu.insert(i);
	}
}

/*
*              。           :  >=6            
*/
void gotbaha(int n){
	prime(n);//   2~n     
	for (int i:sushu){
		for (int j : sushu){
			//  n=          ,   8=3+5 8=5+3    ,          , n     0;
			if (i + j == n&&i<=j){
				cout << n << "=" << i << "+" << j << ";"<<endl;
				cout << n << "      "<<endl;
				n = 0;
				break;
			}
			if (n == 0){
				//  n 0  ,   n      ,       ,        
				break;
			}
		}
	}
}