Created
November 12, 2019 03:59
-
-
Save voith/f63395417b6f6f7d8b294635cb3233ca to your computer and use it in GitHub Desktop.
value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction par
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
largest_num = 1000 | |
largest_divisor = 3 | |
longest_cycle = 1 | |
rdigits = '' | |
def get_divide_result(i): | |
seen_remainders = [False] * i | |
remainder = 10 % i | |
cycle_count = 0 | |
while remainder!= 0 and seen_remainders[remainder] is False: | |
seen_remainders[remainder] = True | |
cycle_count += 1 | |
remainder = (remainder * 10) % i | |
return remainder, cycle_count | |
for i in range(4, largest_num + 1): | |
remainder, cycle_count = get_divide_result(i) | |
if remainder != 0 and cycle_count > longest_cycle: | |
largest_divisor = i | |
longest_cycle = cycle_count | |
print(largest_divisor, longest_cycle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment