feat(solution): problem #27
parent
41f2e5a758
commit
1438f0d8f2
|
|
@ -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)
|
||||||
Loading…
Reference in New Issue