Here are some optimizations you should implement.
First always increment your counter by 2 (only check if odd numbers are prime, 2 is the only even prime number).
Second save a list of the primes you find and instead of checking if a number is prime by dividing by all numbers between 2 and N only try dividing other primes into it. There is no reason to try and divide non prime numbers into it, as they will already be checked via other primes.
|