代码笔记 | 哥德巴赫猜想的计算机验证

 
## 哥德巴赫猜想的计算机验证
  
prime_table = list()
prime_table.append(2)
  
# Check if n is a prime based on existing prime
def is_prime(n):
    for i in prime_table:
        if n%i == 0 and n/i > 1:
            return False
    return True
  
# Update the Prime Table till the max == m
def update_prime(m):
    length = len(prime_table)
    max = prime_table[length-1]
      
    for i in range(max+1, m):
        if is_prime(i):
            prime_table.append(i)
              
def find_plus(even):
    update_prime(even)
    for a in prime_table:
        for b in prime_table:
            if a + b == even:
                return a, b
    print "Guess Failed!"
  
a, b = find_plus(200000)
print "{} = {}+{}".format(e,a,b)

你可能感兴趣的:(计算机,哥德巴赫,代码笔记)