2019-07-16 18:51:07 +02:00
|
|
|
from lib_prime import primes, is_prime
|
2017-08-23 10:01:41 +02:00
|
|
|
|
|
|
|
|
2019-07-16 18:51:07 +02:00
|
|
|
def number_consecutive_primes(a, b):
|
2017-08-23 10:01:41 +02:00
|
|
|
def formula(n):
|
2019-07-16 18:51:07 +02:00
|
|
|
return n * n + a * n + b
|
|
|
|
n = 0
|
|
|
|
while True:
|
2017-08-23 10:01:41 +02:00
|
|
|
if not is_prime(formula(n)):
|
|
|
|
return n
|
2019-07-16 18:51:07 +02:00
|
|
|
n += 1
|
|
|
|
|
|
|
|
|
|
|
|
def euler_027():
|
|
|
|
n_max, a_max, b_max = 0, 0, 0
|
|
|
|
for b in primes(1000):
|
|
|
|
for a in range(-999, 1000):
|
|
|
|
a = -1 * a
|
|
|
|
n = number_consecutive_primes(a, b)
|
|
|
|
if n > n_max:
|
|
|
|
n_max, a_max, b_max = n, a, b
|
|
|
|
return a_max * b_max
|
2017-08-23 10:01:41 +02:00
|
|
|
|
|
|
|
|
2019-07-16 18:51:07 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
print("e027.py: {}".format(euler_027()))
|
|
|
|
assert(euler_027() == -59231)
|