optimize primality test