First 10 Million Prime Numbers

I’ve decided to increase the number from 1,000,000 to 10,000,000.

Surprisingly, this took more than 2.5 hours to calculate.

Also, it takes a long time to open the notepad file, for some reason.

Here’s my code again, in case you wanted to look at it:


import math
text_file = open("Output.txt", "w")

primes = [2, 3]
print("This file was made for cornerspots.com\n1. 2\n2. 3")
text_file.write("This file was made for cornerspots.com\n2\n")
number = 1
rowNumber = 2

while rowNumber < 10000000:
    isPrime = True
    number += 2

    for prime in primes:
        # if number is bigger than the sqrt of num we're checking
        if prime > math.sqrt(number):
            break
        # is not a prime
        if number % prime == 0:
            isPrime = False
            break

    if isPrime:
        rowNumber += 1
        text_file.write(str(number) + "\n")
        primes.append(number)
        print(str(rowNumber) + ". " + str(number))

text_file.close()

And here’s the zip file of my findings:First10MillionPrimeNumbers
Oh, and in case you’re wondering, the 10,000,000th prime number is 179,424,671.
If notepad doesn’t open and instead says not responding, just wait, and it will open eventually. In case notepad doesn’t work for some reason, try notepad++

 

 

Leave a Comment