If I google for "prime number algorithm", I get a lot of suggestions.
Maybe you should also google.
It is enough to end the for-loop if sqrt(n) instead of n/2.
You could save the result of isPrime(2*i+1), because you need it later again for isPrime(i).
Maybe you should also google.
It is enough to end the for-loop if sqrt(n) instead of n/2.
You could save the result of isPrime(2*i+1), because you need it later again for isPrime(i).