Finding particular sequences of prime numbers
Insert your code into consecutive_primes.py so as to find all sequences of 6 consecutive prime 5-digit numbers, say (a,b,c,d,e,f), with b=a+2, c=b+4, d=c+6, e=d+8, and f=e+10. So a, b, c, d, e and f are all 5-digit prime numbers and no number between a and b, between b and c, between c and d, between d and e, and between e and f is prime.If you are stuck, but only when you are stuck, then use consecutive_primes_scaffold.py.
#马丁解法
from math import sqrt
def is_prime(n):
return all(n%d for d in range(3,round(sqrt(n))+1,2)
print('The solutions are:\n')
good_leaps=turple(sum(range(0,k,2)) for k in range(2,13,2))
for a in range(10_001,100_000-good_leaps[-1],2):
if all(((i in good_leaps)==is_prime(a+i) ) for i in range(0,good_leaps[-1],2)):#这里已经完成了两数之间没有素数的判断
for i in good_leaps[:-1]:
print(a+i,end=" ")
print(a+good_leaps[-1])
网友评论