Fermat Primality Test
def fermatPass(n): return n > 1 and ( n == 2 or ( n % 2 != 0 and pow( random.randint( 1, n - 1 ), n - 1, n ) == 1 ) ) def fermatTest(n,k = 10): return all( fermatPass( n ) for i in xrange(k) )