diff --git a/solutions/027/quadraticprimes.py b/solutions/027/quadraticprimes.py new file mode 100644 index 0000000..c691bff --- /dev/null +++ b/solutions/027/quadraticprimes.py @@ -0,0 +1,29 @@ + +import math + +def is_prime(maybeprime): + for i in range(2, math.floor(math.sqrt((abs(maybeprime))) + 1)): + if maybeprime % i == 0: + return False + return True + +def consecutive_primes_in_quadratic_formula(a, b): + n = 0 + while(True): + fx = n * n + a * n + b + if is_prime(fx): + n += 1 + else: + return n + +mostConsecutive = 0 +mostConsecutiveAB = 0 + +for a in range(-999, 999): + for b in range(-1000, 1000): + consecutivePrimes = consecutive_primes_in_quadratic_formula(a, b) + if consecutivePrimes > mostConsecutive: + mostConsecutive = consecutivePrimes + mostConsecutiveAB = a * b + +print("The product of the a & b that produce the most consecutive primes as coefficients in a quadratic formula is: ", mostConsecutiveAB)