Skip to content

Instantly share code, notes, and snippets.

@cedricbellet
Created October 17, 2019 23:12
Show Gist options
  • Save cedricbellet/1347ab9bd56947c896bba8466a4695fe to your computer and use it in GitHub Desktop.
Save cedricbellet/1347ab9bd56947c896bba8466a4695fe to your computer and use it in GitHub Desktop.
from math import gcd
def test_property(candidate: int, max_progression: int=100):
"""Returns True if Fermat's little theorem's property is verified for a
limited number of progressions."""
test_progressions = range(2, max_progression)
for progression in range(2, max_progression):
if gcd(progression, candidate) != 1:
# THIS IS DIFFERENT
# if the progression and the candidate or not co-prime, skip this test
continue
elif (progression ** (candidate - 1)) % candidate != 1:
# the property isn't verified if any of the n-th-1 power mod p is
# a number other than 1
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment