blob: 0ddd85a81bf51bfd6bd3668e17ac8909d28c2c34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
def get_cycle(d):
remainders = []
x = 1
while x > 0:
if x < d:
x *= 10
continue
z = x / d
x = (x % d) * 10
if x in remainders: # cycle detected
pos = 0
for i in range(len(remainders)):
if remainders[i] == x:
return len(remainders) - i
break
remainders += [x]
return 0 # no cycle
max_remainder = 0
result = 0
for i in range(1, 1000):
r = get_cycle(i)
if r > max_remainder:
max_remainder = r
result = i
print result
|