Created
June 28, 2013 13:48
-
-
Save Ayrx/5884802 to your computer and use it in GitHub Desktop.
Python implementation of the Fermat Primality Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fermat_test(n, k): | |
# Implementation uses the Fermat Primality Test | |
# If number is even, it's a composite number | |
if n == 2: | |
return True | |
if n % 2 == 0: | |
return False | |
for i in xrange(k): | |
a = random.randint(1, n-1) | |
if pow(a, n-1) % n != 1: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Waouh, that is cool.
Did you found a prime number using this method? like a prime number with 10^3 digit?