My task is to produce an array containing all the prime numbers up to a 12-digit number.
I tried to emulate the Sieve of Eratosthenes by first making a function e
up to 12 digits is 100,000,000,000. That's a lot of primes (~ N/log N = 3,948,131,653).
So, make a sieve up to 10^6, compress it into the array of ~78,500 core primes, and use them to sieve segment by segment all the way up to your target. Use primes up to the square root of the current upper limit of the segment. The size of the segment is usually chosen so that it fits into system cache. After sieving each segment, collect its primes.
This is known as segmented sieve of Eratosthenes.