Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Created June 28, 2013 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 Mar 16, 2021

Waouh, that is cool.
Did you found a prime number using this method? like a prime number with 10^3 digit?

@andWhatShouldISay
Copy link

binary exponention with a modulo? не, не слышали

@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