Advertisement
banovski

Project Euler, Problem #7, Python

Dec 20th, 2021 (edited)
1,181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. # By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we
  4. # can see that the 6th prime is 13. What is the 10 001st prime number?
  5.  
  6. primes_list = [2]
  7. current_number = 3
  8. primes_number = 1
  9.  
  10. while primes_number <= 10001:
  11.     for i in primes_list:
  12.         if current_number % i == 0:
  13.             break
  14.     else:
  15.         primes_list.append(current_number)
  16.         primes_number += 1
  17.         output = current_number
  18.        
  19.     current_number += 1
  20.  
  21. print(output)
  22.  
  23. # 104743
  24. # 10004 function calls in 12.344 seconds
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement