-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path027.py
More file actions
38 lines (33 loc) · 657 Bytes
/
027.py
File metadata and controls
38 lines (33 loc) · 657 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
33
34
35
36
37
38
import math, itertools
primelist = [2]
for i in range(2,10000):
divides = 0
for x in primelist:
if i%x == 0:
divides = 1
break
if not divides:
primelist.append(i)
def f(n, a, b):
return n*n + a*n + b
maxcount = 0
maxa = 0
maxb = 0
for a in range(-1000, 1000):
for b in primelist:
if b > 999:
break
count = 0
for n in itertools.count(0):
if f(n, a, b) in primelist:
count += 1
else:
break
if count > maxcount:
maxcount = count
maxa = a
maxb = b
print maxa, maxb, maxcount
for i in range(0, maxcount):
print i, f(i, maxa, maxb)
print 'answer:', maxa*maxb