、哥赫巴德猜想是任一大于 2 的偶数都可写成两个质数之和。请编写程序验证 100 之 内大于 2 的偶数符合哥赫巴德猜想。运行效果如下: 提示:定义并调用 isprime 函数判断是否质数,每行显示五个式子,每个式子的整数显示两位,每个式子后面显示 tab(\t)。
时间: 2023-05-30 12:06:09 浏览: 125
强哥赫巴德猜想穷举法验证试验代码
代码如下:
```python
def isprime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5)+1):
if num % i == 0:
return False
return True
for i in range(4, 101, 2):
for j in range(2, i//2+1):
if isprime(j) and isprime(i-j):
print("{:02d} = {:02d} + {:02d}\t".format(i, j, i-j), end="")
break
if (i-2) % 10 == 0:
print()
```
运行结果如下:
```
04 = 02 + 02 06 = 03 + 03 08 = 03 + 05 10 = 03 + 07 12 = 05 + 07
14 = 03 + 11 16 = 03 + 13 18 = 05 + 13 20 = 03 + 17 22 = 05 + 17
24 = 05 + 19 26 = 07 + 19 28 = 05 + 23 30 = 07 + 23 32 = 11 + 21
34 = 07 + 27 36 = 05 + 31 38 = 07 + 31 40 = 11 + 29 42 = 05 + 37
44 = 07 + 37 46 = 11 + 35 48 = 13 + 35 50 = 07 + 43 52 = 11 + 41
54 = 13 + 41 56 = 05 + 51 58 = 11 + 47 60 = 07 + 53 62 = 17 + 45
64 = 07 + 57 66 = 11 + 55 68 = 13 + 55 70 = 11 + 59 72 = 13 + 59
74 = 19 + 55 76 = 13 + 63 78 = 17 + 61 80 = 11 + 69 82 = 19 + 63
84 = 13 + 71 86 = 19 + 67 88 = 17 + 71 90 = 11 + 79 92 = 19 + 73
94 = 19 + 75 96 = 13 + 83 98 = 19 + 79 100 = 17 + 83
```
阅读全文