Skip to content

Instantly share code, notes, and snippets.

@voith
Created May 13, 2022 19:45
Show Gist options
  • Save voith/f2808943501bee5900421efa82fbfce5 to your computer and use it in GitHub Desktop.
Save voith/f2808943501bee5900421efa82fbfce5 to your computer and use it in GitHub Desktop.
The Reciprocals of Primes
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