Refactor for efficiency
This commit is contained in:
@@ -37,11 +37,17 @@ def compute():
|
||||
|
||||
cycle_length = 0
|
||||
ans = 0
|
||||
# Because denominators with factor 2 contribute only to the terminating
|
||||
# part of a decimal. The repeating behavior comes from the part of the
|
||||
# denominator that is coprime with 10, so evens are skipped
|
||||
for number in range(3, 1000, 2):
|
||||
if number % 5 == 0:
|
||||
continue
|
||||
p = 1
|
||||
while 10**p % number != 1:
|
||||
remainder = 10 % number
|
||||
while remainder != 1:
|
||||
# avoid huge exponentiation
|
||||
remainder = (remainder * 10) % number
|
||||
p += 1
|
||||
if p > cycle_length:
|
||||
cycle_length, ans = p, number
|
||||
|
||||
Reference in New Issue
Block a user