Speedup of primality check