There are only 100,000 possible 5 digit sequences, so at some point any input will start repeating.(只有100,000个可能的5位数字序列,因此在某个时候任何输入都会开始重复。)
Use a hash to find out when your input sequence has started repeating.(使用散列找出输入序列何时开始重复。) Calculate the cycle length.(计算循环长度。) Subtract the max possible full cycles and continue with the remainder.(减去最大可能的完整循环,然后继续其余的循环。)
Running time is O(10^r) where r is the sequence length.(运行时间为O(10 ^ r),其中r是序列长度。) This is bad for large r but fine for r=5(这对大r不利,但对r = 5有利) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…