Skip to content

Instantly share code, notes, and snippets.

@amoshyc
Created February 7, 2015 13:55
Show Gist options
  • Save amoshyc/b4ffcb08f04c397ab41b to your computer and use it in GitHub Desktop.
Save amoshyc/b4ffcb08f04c397ab41b to your computer and use it in GitHub Desktop.
Project Euler #7
def is_prime(N, primes):
    for p in primes:
        if p * p > N:
            return True
        if N % p is 0:
            return False
    return True

primes = [2, 3, 5, 7]
query = 11
while len(primes) < 10001:
    if is_prime(query, primes):
        primes.append(query)
    query += 2

print(primes[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment