Created
October 17, 2019 23:12
-
-
Save cedricbellet/1347ab9bd56947c896bba8466a4695fe to your computer and use it in GitHub Desktop.
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
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