Created
May 13, 2022 19:45
-
-
Save voith/f2808943501bee5900421efa82fbfce5 to your computer and use it in GitHub Desktop.
The Reciprocals of Primes
This file contains hidden or 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 repeating_digit(num: int) -> int: | |
""" | |
code inspired by | |
The Reciprocals of Primes - Numberphile | |
on youtube: https://www.youtube.com/watch?v=DmfxIhmGPP4&ab_channel=Numberphile | |
Parameter | |
num: a prime number | |
returns: The number of repeating digits of reciprocal of a prime number | |
""" | |
digits = len(str(num)) | |
remainders = set() | |
remainder = 1 | |
count = 0 | |
while remainder not in remainders and count < num: | |
count += 1 | |
remainders.add(remainder) | |
remainder = (remainder * 10 ** digits) % num | |
return count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment