project-euler-100

[RADIOACTIVE] solutions to the first 100 challenges of project euler
git clone git://git.figbert.com/project-euler-100.git
Log | Files | Refs | README

problem007.py (829B)


      1 # problemName = "10001st prime"
      2 # problemNum = 7
      3 # solutionBy = "FIGBERT"
      4 # language = "Python"
      5 # dateCompleted = "24/01/2020"
      6 
      7 def sieve_of_eratosthenes(limit):
      8     prime = [True for _ in range(limit+1)]
      9     prime_pos = 2
     10     while (prime_pos**2 <= limit): 
     11         if (prime[prime_pos] == True): 
     12             for i in range(prime_pos * 2, limit + 1, prime_pos): 
     13                 prime[i] = False
     14         prime_pos += 1
     15     prime[0:2] = [False, False]
     16     return [prime_pos for prime_pos in range(limit + 1) if prime[prime_pos]]
     17 
     18 if __name__ == "__main__":
     19     search_range = 1000
     20     return_value = sieve_of_eratosthenes(search_range)
     21     while len(return_value) < 10001:
     22         search_range += 1000
     23         return_value = sieve_of_eratosthenes(search_range)
     24     print("The 10,001st prime number is %s" % return_value[10000])