princeofsudan

ProjectEuler#7 10001st prime

Mar 2nd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. #By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
  2.  
  3. #What is the 10 001st prime number?
  4.  
  5. #isPrime algorithm from MIT 6.00x course notes
  6.  
  7. def isPrime(n):
  8.     '''check if integer n is a prime'''
  9.     # range starts with 2 and only needs to go up the square-root of n
  10.     for x in range(2, int(n**0.5)+1):
  11.         if n % x == 0:
  12.             return False
  13.     return True
  14.  
  15. count = 0
  16. i = 2
  17. while count < 10001:
  18.     if isPrime(i):
  19.         count += 1
  20.     i += 1
  21.  
  22. print i-1
Advertisement
Add Comment
Please, Sign In to add comment