很没有效率的暴力解法def is_prime(n):
if n<2: return False
for p in (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97):
if pow(p,n-1,n) != 1:
return False
return True
def solve(limit):
n = 0
for i in range(1,limit//10):
t1 = 10*i
t2 = 10*i+2
t3 = 10*i+8
if is_prime(t3*t3+1) and is_prime(t3*t3+3) and is_prime(t3*t3+7) and is_prime(t3*t3+9) and is_prime(t3*t3+13) and is_prime(t3*t3+27) and not is_prime(t3*t3+19) and not is_prime(t3*t3+21):
n += t3
continue
if is_prime(t2*t2+1) and is_prime(t2*t2+3) and is_prime(t2*t2+7) and is_prime(t2*t2+9) and is_prime(t2*t2+13) and is_prime(t2*t2+27) and not is_prime(t2*t2+19) and not is_prime(t2*t2+21):
n += t2
continue
if is_prime(t1*t1+1) and is_prime(t1*t1+3) and is_prime(t1*t1+7) and is_prime(t1*t1+9) and is_prime(t1*t1+13) and is_prime(t1*t1+27) and not is_prime(t1*t1+19) and not is_prime(t1*t1+21):
n += t1
continue
return n
print(solve(150000000))
676333270
[Finished in 993.5s] |