It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.
\[9 = 7 + 2×1^2\] \[15 = 7 + 2×2^2\] \[21 = 3 + 2×3^2\] \[25 = 7 + 2×3^2\] \[27 = 19 + 2×2^2\] \[33 = 31 + 2×1^2\]It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
import math
def is_Prime(number):
if number < 2:
return False
for x in range(2, int(math.sqrt(number)) + 1):
if number % x == 0:
return False
return True
i = 2
while True:
i += 1
odd = 2 * i - 1
if is_Prime(odd):
continue
result = False
for p in range(2, odd):
if not is_Prime(p):
continue
m = odd - p
if not m % 2 == 0:
continue
m /= 2
if not int(math.sqrt(m))**2 == m:
continue
m = int(math.sqrt(m))**2
result = True
#print "%s = %s + 2 x %s ^ 2" % (odd, p, m)
break
if not result:
print odd
exit(0)
这题是几天前完成的了,感想忘了。好像看到歌德巴赫就想到了陈景润……我就记得好像跑得没有1.4S(解开print)/0.9S(注解print)那么快的样子,难道真的是家里电脑更好?