Skip to content

Instantly share code, notes, and snippets.

@ssanin82
Created February 6, 2015 09:16
Show Gist options
  • Save ssanin82/42af9ef3729e3b8c8134 to your computer and use it in GitHub Desktop.
Save ssanin82/42af9ef3729e3b8c8134 to your computer and use it in GitHub Desktop.
def get_cycle_len(num):
found_remainders = [0] * num
value = 1
position = 0
while not found_remainders[value] and value:
found_remainders[value] = position
value *= 10
value %= num
position += 1
return 0 if not value else position - found_remainders[value]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment