Various primality testing code.