Just a small mildly optimized function to check if an integer is a prime number. For very large numbers use the Miller-Rabin primality test.
There have been questions why I used
not n & 1 to check for even integer n. The more tradional
n % 2 == 0 is about 30% slower. So I gained a tiny bit more speed.