4 ms·
You don't need to test up to n/2, just floor(sqrt(n)) will do even better you only need to test the primes <= floor(sqrt(n))
by PirateAvogadro 5y ago
You don't need to test up to n/2, just floor(sqrt(n)) will do
even better you only need to test the primes <= floor(sqrt(n))