from lib_prime import primes, is_prime def number_consecutive_primes(a, b): def formula(n): return n * n + a * n + b n = 0 while True: if not is_prime(formula(n)): return n 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 if __name__ == "__main__": print("e027.py: {}".format(euler_027())) assert(euler_027() == -59231)