to calculate one million prime numbers

If you added 1 to your list, your answer is wrong already :)

Anyway, Sieve of Erathosthenes is where you should begin, it's incredibly simple and quite efficient.

Once you're familiar with the idea of sieves and how they work, you can move on to Sieve of Atkin, which is a bit more complicated but obviously more efficient.


Key things:

  1. Skip all even numbers. Start with 5, and just add two at a time.
  2. 1 isn't a prime number...
  3. Test a number by finding the mod of all prime numbers till the square root of the number. No need to test anything but primes.

You might want to implement Sieve of Eratosthenes algorithm to find prime numbers from 1 to n and iteratively increase the range while you are doing it if needed to. (i.e. did not find 1,000,000 primes yet)