Last active
January 2, 2016 18:39
-
-
Save kaipakartik/8345235 to your computer and use it in GitHub Desktop.
Problem 7
Project Euler By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prime(n): | |
primes = [2] | |
start = 3 | |
while len(primes) <= n: | |
isPrime = True; | |
for prime in primes: | |
if start % prime == 0: | |
isPrime = False; | |
break; | |
if isPrime: | |
primes = primes + [start] | |
start = start + 2 | |
print primes[n-1] | |
prime(6) | |
prime(10001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment