Where can I download a full list of all primes below $10^{15}$?

3.3k Views Asked by At

I would like to do some computing on a large list of primes. Unfortunately my computer is not strong enough to quickly generate such a list, so I'm looking to download a file that already contains these numbers.

Specifically, I would like to have a list of all primes up to $10^{15}$, preferably in CSV format. After googling for a while, I found no such list on the internet. There is this website, but it does not allow to download all numbers in one list.

3

There are 3 best solutions below

2
On BEST ANSWER

The prime number theorem says that there are about $3 \cdot 10^{13}$ primes less than $10^{15}$. If each prime took one byte, the file would be at least 10 terabytes long. Not something that will be readily available for download. A bitmap would take 125 terabytes, again not feasible.

2
On

You can generate your own primes in vertical order in csv format using a simple R code. I generated primes up to 1 billion primes in about an hour using a regular 8GB RAM laptop. You can change the range and run it as per your convenience.

Download and install R then download and install RStudio

Open RStudio, copy the code below and click run

install.packages("data.table")
install.packages("numbers")
install.packages("primes")
library(data.table)
library(numbers)
library(primes)

primes = as.data.frame(generate_primes(max = 10^9))
colnames(primes) = c("p_n")
fwrite(primes,"C:/New_Folder/Mathdata/prime_list.csv", row.names = F)
1
On

List of primes less than 10^15? Obviously, you do not know what you really want! According to prime theorem there are 28952965460217 primes less than 10^15. Basically, prime theorem underestimates number of primes in this area (billions, trillions) in about 3-4%. We actually know the exact number of primes less than 10^15 and the are exactly 29844570422669 primes less than 10^15. Approximately 90% of the primes have 15 digits, 9% of them have 14 gidits, 0,9% of them have 13 digits …etc. You can save them to file each prime on new line, but the new line or Enter is presented by bytes witn hexadecimal values "0D 0A", so there would be two additional bytes after each prime. For data saving we can have ten primes in one line, each prime separated by tabulator (witn hexadecimal values "09") or space (with hexadecimal values "20") or any 1-byte char in general. Do not forget the two additional bytes after every 10-th prime, these two additional bytes after after every 10-th prime represents new line or Enter. So we have approximately 90% of 15 digit prime from 10^14 to 10^15. The are 26639628671867 such 15 digit primes. One line containing ten of them would have 10x15 bytes for primes themselves + 1x9 bytes for any 1-byte char separator and two additional bytes at the end of the line. One line is 10x15+1x9+2 = 150+9+2 = 161 bytes and there must be nearly 2663962867187 such lines in the list. So that is 2663962867187x161 = 428898021617107 bytes with couple of bytes added. Really only a couple of bytes added. With the same math and prime number theorem (basically we know the exact number of primes up to 10^25), we can find out what space we need for the 9% amount. There are exactly 2858876213963 individual 14 digit primes between 10^13 and 10^14. Again, lines with ten primes in each line …etc. and this would require 151x285887621397 = 43169030830947 bytes. The other 0,9% would require again 10-times less data space, cca 4300000000000 bytes. The other 0,09% would require again 10-times less data space, cca 430000000000 bytes. The other 0,009% would require again 10-times less data space, cca 43000000000 bytes. So finally we would need cca 476844830221054 of bytes to save the list! It is nearly 477 TB (terabytes). Where do you want store it? It is observed this kind of data are packed with lossless compression with 80% efficiency, so 20% still remains. OK, after packing with the best lossless compression/packer (RAR, 7Z, PPM, LZMA…) you would still need nearly 100 TB of disk space! Still wandering you did not find such kind of list? Because it is not feasible. It does not exist for offline downloading .