forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp046.py
More file actions
33 lines (26 loc) · 697 Bytes
/
p046.py
File metadata and controls
33 lines (26 loc) · 697 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
#
# Solution to Project Euler problem 46
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
import eulerlib, itertools, sys
if sys.version_info.major == 2:
filterfalse = itertools.ifilterfalse
else:
filterfalse = itertools.filterfalse
def compute():
ans = next(filterfalse(test_goldbach, itertools.count(9, 2)))
return str(ans)
def test_goldbach(n):
if n % 2 == 0 or eulerlib.is_prime(n):
return True
for i in itertools.count(1):
k = n - 2 * i * i
if k <= 0:
return False
elif eulerlib.is_prime(k):
return True
if __name__ == "__main__":
print(compute())