only calculate primes up to Math.sqrt(n)