forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp007.py
More file actions
26 lines (21 loc) · 852 Bytes
/
p007.py
File metadata and controls
26 lines (21 loc) · 852 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
#
# Solution to Project Euler problem 7
# 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:
filter = itertools.ifilter
# Computers are fast, so we can implement this solution by testing each number
# individually for primeness, instead of using the more efficient sieve of Eratosthenes.
#
# The algorithm starts with an infinite stream of incrementing integers starting at 2,
# filters them to keep only the prime numbers, drops the first 10000 items,
# and finally returns the first item thereafter.
def compute():
ans = next(itertools.islice(filter(eulerlib.is_prime, itertools.count(2)), 10000, None))
return str(ans)
if __name__ == "__main__":
print(compute())