feat(solution): problem #27

main
steven 2023-08-01 16:32:11 -04:00
parent 41f2e5a758
commit 1438f0d8f2
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
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)