嵇爾的吐槽

#没事画轮子的嵇尔不定期的(W)碎(E)碎(B)念(B)和(L)吐(O)槽(G)

Problem 46 Goldbach's other conjecture 2016-11-08 22:11:04

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×12

15 = 7 + 2×22

21 = 3 + 2×32

25 = 7 + 2×32

27 = 19 + 2×22

33 = 31 + 2×12

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)那么快的样子,难道真的是家里电脑更好?

评论共