-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp027.py
More file actions
32 lines (31 loc) · 991 Bytes
/
Copy pathp027.py
File metadata and controls
32 lines (31 loc) · 991 Bytes
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
from euler import sieve_eratosthenes
import time
timer = time.time
if __name__ == '__main__':
tStart = timer()
# b has to be prime as n=0 should be prime
b_list = sieve_eratosthenes(1000)
# generate all primes below 10**5 for checking for primality
primes = sieve_eratosthenes(10**5)
primes = set(primes)
res_cnt = 0
res = 0
res_a, res_b = 0, 0
# a should be odd as 1**2 + 1*a + b should be prime/odd
for a in range(-999, 1000, 2):
for b in b_list:
n = 0
while True:
tmp = n**2 + n*a + b
if tmp in primes:
pass
else:
break
n += 1
if res_cnt < n+1:
res = a*b
res_a, res_b = a, b
res_cnt = n+1
print('Product %d*%d = %d, Number of primes: %d' % (res_a, res_b, res, res_cnt))
tEnd = timer()
print('Time taken: %f seconds' % (tEnd - tStart))