-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem 27G.py
38 lines (29 loc) · 1.11 KB
/
Problem 27G.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Runtime - 250 milliseconds (0.250 seconds)
from myFunctionsG import execute_this, prime_checker as isprime, sieveEratoAlt as generatePrimes
@execute_this
def Problem_27():
bestResult = {"MaximumPrimes": int(), "Product": int()}
def quadraticiterator(a, b):
num = 0
while True:
yield (num ** 2 + a * num + b)
num += 1
for a in generatePrimes(1000):
for b in generatePrimes(1000):
primesFound = 0
for x in quadraticiterator(a, b):
if isprime(x):
primesFound += 1
else:
break
if primesFound > bestResult["MaximumPrimes"]:
bestResult["MaximumPrimes"], bestResult["Product"] = primesFound, a*b
primesFound = 0
for x in quadraticiterator(-a, b):
if isprime(x):
primesFound += 1
else:
break
if primesFound > bestResult["MaximumPrimes"]:
bestResult["MaximumPrimes"], bestResult["Product"] = primesFound, -a*b
print(bestResult)