def fd(n):
x,y,count1,count2 = n,1,0,0
while (x > 1): (x,count1) = (x/5,1+count1)
while (y < n): (y,count2) = (count1+y,1+count2)
return count2
请您参考如下方法:
让我们看看。第一个循环计算 n 可以被 5 除多少次,所以 count1 是 log(n)(常数不计入 O() 计算)。然后第二个循环统计count1(=log(n))多少次可以加到1得到n,所以基本上是循环for n/log(n ) 次。
在我看来这是 O(log(n) + (n/log(n)))。
正如 J.F. Sebastian 指出的,n/log(n) 支配 log(n),所以最终答案应该是 O(n/log(n))。
