p007.py 852 Bytes
 Nayuki Minase committed Jul 19, 2015 1 2 ``````# # Solution to Project Euler problem 7 `````` Nayuki committed Dec 27, 2016 3 ``````# Copyright (c) Project Nayuki. All rights reserved. `````` Nayuki Minase committed Jul 19, 2015 4 ``````# `````` Nayuki Minase committed Feb 05, 2016 5 ``````# https://www.nayuki.io/page/project-euler-solutions `````` Nayuki Minase committed Jul 19, 2015 6 7 8 ``````# https://github.com/nayuki/Project-Euler-solutions # `````` Nayuki Minase committed Feb 29, 2016 9 10 11 ``````import eulerlib, itertools, sys if sys.version_info.major == 2: filter = itertools.ifilter `````` Nayuki Minase committed Jul 22, 2015 12 `````` `````` Nayuki Minase committed Jul 19, 2015 13 `````` `````` Nayuki Minase committed Mar 12, 2016 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. `````` Nayuki Minase committed Jul 22, 2015 20 ``````def compute(): `````` Nayuki Minase committed Feb 29, 2016 21 22 `````` ans = next(itertools.islice(filter(eulerlib.is_prime, itertools.count(2)), 10000, None)) return str(ans) `````` Nayuki Minase committed Jul 22, 2015 23 24 25 26 `````` if __name__ == "__main__": print(compute())``````