p007.py 852 Bytes
Newer Older
1 2
# 
# Solution to Project Euler problem 7
3
# Copyright (c) Project Nayuki. All rights reserved.
4
# 
5
# https://www.nayuki.io/page/project-euler-solutions
6 7 8
# https://github.com/nayuki/Project-Euler-solutions
# 

9 10 11
import eulerlib, itertools, sys
if sys.version_info.major == 2:
	filter = itertools.ifilter
12

13

14 15 16 17 18 19
# 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.
20
def compute():
21 22
	ans = next(itertools.islice(filter(eulerlib.is_prime, itertools.count(2)), 10000, None))
	return str(ans)
23 24 25 26


if __name__ == "__main__":
	print(compute())