验证哥德巴赫猜想

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>  
using namespace std;

int judge(int);

int main()
{
cout << "验证哥德巴赫猜想:一个不小于6的偶数可以表示为两个素数之和" << endl << endl;

int border, num, front;

cout << "请输入欲验证的最大值:";
cin >> border;

for (num = 6; num <= border; num = num + 2)
{
for (front = 3; front <= num / 2; front = front + 2)
{
//先把num表示为front和另一个奇数behind之和,再判断这两个奇数是否为素数
int behind = num - front;

if ((judge(front) == 1) & (judge(behind) == 1))
{
cout << num << "=" << front << "+" << behind << endl;
}
}
}

system("pause");
return 0;
}

int judge(int tmp)
{
for (int i = 3; i <= sqrt(tmp); i = i + 2)
{
if (tmp % i == 0) return 0; //只要能被一个奇数整除,它就不是素数
}

//要遍历所有奇数才能说它是素数
return 1;
}

验证哥德巴赫猜想
https://roachlin.github.io/2021-12-05-goldbach-conjecture/
作者
RoachLin
发布于
2021年12月5日
许可协议