importitertoolsm=1000max_cycle=0number=0foriinrange(1,m):whilei%2==0:i=i/2whilei%5==0:i=i/5forjinitertools.count(1):if(10**j-1)%i==0:length=j#printlengthbreakiflength>max...
import itertools
m = 1000
max_cycle = 0
number = 0
for i in range(1,m):
while i%2 == 0:
i = i/2
while i%5 == 0:
i = i/5
for j in itertools.count(1):
if (10**j-1)%i == 0:
length = j
# print length
break
if length > max_cycle:
number = i
max_cycle = length
print number
===========================================
max=0;
n=0;
for i=1:1000
while mod(i,2)==0
i=i./2;
end
while mod(i,5)==0
i=i./5;
end
for j=1:inf
if mod((10^j-1),i)==0
l=j;
break
end
end
if l>=max
n=i;
max=l;
end
end
n
这是我自己改的运行的答案不对。
展开