-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem46.py
executable file
·48 lines (47 loc) · 974 Bytes
/
problem46.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
39
40
41
42
43
44
45
46
47
48
# coding: utf-8
def primeGen():
q = 2
D = {}
while True:
if q not in D:
yield q
D[q*q] = [q]
else:
for p in D[q]:
D.setdefault(p+q, []).append(p)
del D[q]
q += 1
def isPrime(x):
if x == 1:
return False
for i in xrange(2, int(x ** 0.5) + 1):
if x % i == 0:
return False
return True
def oddComp():
q = 9
while True:
if not isPrime(q):
yield(q)
q += 2
def squares():
start = 1
while True:
yield start * start
start += 1
def main():
a = oddComp()
x = a.next()
b = squares()
y = b.next()
squareList = []
while True:
while y * 2 < x:
squareList.append(y * 2)
y = b.next()
if any(isPrime(x - i) for i in squareList):
pass
else:
return x
break
x = a.next()