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
def fd(n): x,y,count1,count2 = n,1,0,0 while (x > 1): (x,count1) = (x/5,1+count1) while (y
Share
Let’s see. The first loop counts how many times
ncan be divided by 5, socount1is log(n) (constants don’t count for O() calculations). Then the second loop counts how many timescount1(= log(n)) can be added to 1 to get ton, so it basically loops for n / log(n) times.It looks to me like this is O(log(n) + (n/log(n))).
As J.F. Sebastian points out, n/log(n) dominates log(n), so the final answer should be O(n/log(n)).