Posted By

chroto on 05/21/10


Tagged


Versions (?)

Project Euler - Problem 7


 / Published in: Python
 

  1. #!/usr/bin/python
  2.  
  3. # Project Euler - Problem 7
  4. # Find the 10001st prime number
  5.  
  6. # Primes are divisible only by themselves
  7.  
  8. num = 10001
  9.  
  10. cnt = 1
  11.  
  12. x = 2
  13.  
  14. primes = [2]
  15.  
  16. while cnt < num:
  17. x = x + 1
  18. isPrime = True
  19. for i in primes:
  20. if x % i == 0:
  21. isPrime = False
  22. break
  23. if isPrime:
  24. primes.append(x)
  25. cnt = cnt + 1
  26.  
  27. print x

Report this snippet  

You need to login to post a comment.