使用python基本知识验证哥德巴赫猜想

def isprime(num):
	i = 2
	while(i<num):
		if num%i==0:
			return False
		i += 1
	return True

def goldbachresolve(num):
	for i in range(2,num):
		if isprime(i) and isprime(num-i):
			print(num,'=',i,'+',num-i)
			return True
	return False
times=10000
i=4
while(goldbachresolve(i) and i<times):
	i += 2
if i==times:
	print("Goldbach hypothesis is proven in the given range.")
else:
	print("Goldbach hypothesis is proven wrong!")
发布了273 篇原创文章 · 获赞 40 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_41855010/article/details/105256609