Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Created June 28, 2013 13:48
Show Gist options
  • Save Ayrx/5884802 to your computer and use it in GitHub Desktop.
Save Ayrx/5884802 to your computer and use it in GitHub Desktop.
Python implementation of the Fermat Primality Test
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
@bm777
Copy link

bm777 commented Dec 5, 2022

Difficult right? @andWhatShouldISay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment