Is there any formula to compute $\sum\limits_{i=1}^{i=k}\lfloor{\frac{n}{5^i}\rfloor}$?

This is the formula we use to calculate the number of trailing zeros in $n!$ but we have to add the individual elements of the sum to get up with an answer. Is there any way we can bypass that?

• For a generic $n$, I think that there is no magic formula... – Robert Z Oct 11 '16 at 14:03

Let $r=1/5$.

Without the floor function, we have

$$\sum_{i=1}^knr^i=n\frac{r-r^{k+1}}{1-r}$$

With the floor function, we have

$$\sum_{i=1}^k\left\lfloor nr^i\right\rfloor\le\left\lfloor n\frac{r-r^{k+1}}{1-r}\right\rfloor$$

We also have that for $k\ge a=\lceil\log_{1/r}(n)\rceil:$

$$\sum_{i=1}^k\left\lfloor nr^i\right\rfloor=\sum_{i=1}^a\left\lfloor nr^i\right\rfloor\le\left\lfloor n\frac{r-r^{a+1}}{1-r}\right\rfloor$$

which seems to be pretty close to the correct value.