Return all primes up to n.
Note that if you need a specific number of primes, you can use the fact the distance from one prime to the next is on average proportional to the logarithm of the prime. Integrating, you find that there are about k primes less than k \log ( 5 k ).
The algorithm used is called the Sieve of Erastothenes.