-
Notifications
You must be signed in to change notification settings - Fork 0
/
PE046.py
40 lines (36 loc) · 855 Bytes
/
PE046.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
oddComposite = 9
canBeWritten = True
def isPrime(inp):
if inp < 2:
return False
if inp == 2:
return True
if not inp % 2:
return False
fact = 3
while fact < inp**0.5+1:
if not inp % fact:
return False
fact += 2
return True
def findOddPrimes(inp):
res = []
next = 3
while next <= inp:
if isPrime(next):
res.append(next)
next += 2
return res
# prime + 2*(n**2)
while canBeWritten:
if not isPrime(oddComposite):
canBeWritten = False
for prime in findOddPrimes(oddComposite):
sq = (oddComposite - prime)//2
if int(sq**0.5)**2 == sq:
canBeWritten = True
break
if not canBeWritten:
print(oddComposite)
break
oddComposite += 2