So, If we were to calculate the first billion primes how much ram would we need?
At the end the primes won't fit in a 32bit integer. If we store them all in 64bit integers we'd need 8GB.
Even if they all fit in 32bit integers we'd still need 4GB of storage just to store the list.
Seeing at my little machine has 4GB ram that isn't going to work either.
How about just storing the intervals between primes?
For the first primes (2, 3, 5, 7, 11, 13, 17) we would store (2, 1, 2, 2, 4, 2, 4)
Using a byte for every interval less than 128 and a short for the rest lets us store the first billion primes in just about 1GB. Now that we can do!
Maybe we can do even better though...
At the end the primes won't fit in a 32bit integer. If we store them all in 64bit integers we'd need 8GB.
Even if they all fit in 32bit integers we'd still need 4GB of storage just to store the list.
Seeing at my little machine has 4GB ram that isn't going to work either.
How about just storing the intervals between primes?
For the first primes (2, 3, 5, 7, 11, 13, 17) we would store (2, 1, 2, 2, 4, 2, 4)
Using a byte for every interval less than 128 and a short for the rest lets us store the first billion primes in just about 1GB. Now that we can do!
Maybe we can do even better though...
Comments
Post a Comment