<s>[INST] What is the number of trailing zeros in a factorial in base ‘b’? I know the formula to calculate this, but I don't understand the reasoning behind it:
For example, the number of trailing zeros in $100!$ in base $16$:
$16=2^4$,
We have:
$\frac{100}{2}+\frac{100}{4}+\frac{100}{8}+\frac{100}{16}+\frac{100}{32}+\frac{100}{64}=97$
Number of trailing zeros$ =\frac{97}{4} = 24$.
Why do we divide by the power of '$2$' at the end?
 [/INST] Suppose that $b=p^m$, where $p$ is prime; then $z_b(n)$, the number of trailing zeroes of $n!$ in base $b$, is 
$$z_b(n)=\left\lfloor\frac1m\sum_{k\ge 1}\left\lfloor\frac{n}{p^k}\right\rfloor\right\rfloor\;.\tag{1}$$
That may look like an infinite summation, but once $p^k>n$, $\left\lfloor\frac{n}{p^k}\right\rfloor=0$, so there are really only finitely many non-zero terms.
The summation counts the number of factors of $p$ in $n!$. The set $\{1,2,\dots,n\}$ of integers whose product is $n!$ contains $\left\lfloor\frac{n}p\right\rfloor$ multiples of $p$, $\left\lfloor\frac{n}{p^2}\right\rfloor$ multiples of $p^2$, and so on $-$ in general $\left\lfloor\frac{n}{p^k}\right\rfloor$ multiples of $p^k$. Each multiple of $p$ contributes one factor of $p$ to the product $n!$; each multiple of $p^2$ contributes an additional factor of $p$ beyond the one that was already counted for it as a multiple of $p$; each multiple of $p^3$ contributes an additional factor of $p$ beyond the ones already counted for it as a multiple of $p$ and as a multiple of $p^2$; and so on.
Let $s=\sum_{k\ge 1}\left\lfloor\frac{n}{p^k}\right\rfloor$; then $n!=p^sk$, where $k$ is not divisible by $p$. Divide $s$ by $m$ to get a quotient $q$ and a remainder $r$: $s=mq+r$, where $0\le r<m$. Then $$n!=p^sk=p^{mq+r}k=(p^m)^qp^rk=b^qp^rk\;,$$ where $p^rk$ is not divisible by $b$. Since $p^rk$ isn’t divisible by $b$, in base $b$, it will not end in $0$. Multiplying it by $b$ will simply tack a $0$ on the righthand end of it, just as multiplying $123$ by $10$ in base ten tacks a $0$ on the end to make $1230$. Multiplying by $b^q$ is multiplying by $b$ a total of $q$ times, so it tacks $q$ zeroes onto a number that did not end in $0$; the result is that $n!$ ends up with $q$ zeroes in base $b$. But $$q=\left\lfloor\frac{s}m\right\rfloor=\left\lfloor\frac1m\sum_{k\ge 1}\left\lfloor\frac{n}{p^k}\right\rfloor\right\rfloor\;,$$ showing that $(1)$ is correct.
In your example $b=2^4$, so $p=2$ and $m=4$, and with $n=100$, $(1)$ becomes
$$\begin{align*}
z_{16}(100)&=\left\lfloor\frac14\sum_{k\ge 1}\left\lfloor\frac{100}{2^k}\right\rfloor\right\rfloor\\\\
&=\left\lfloor\frac14\left(\left\lfloor\frac{100}2\right\rfloor+\left\lfloor\frac{100}4\right\rfloor+\left\lfloor\frac{100}8\right\rfloor+\left\lfloor\frac{100}{16}\right\rfloor+\left\lfloor\frac{100}{32}\right\rfloor+\left\lfloor\frac{100}{64}\right\rfloor\right)\right\rfloor\\\\
&=\left\lfloor\frac14(50+25+12+6+3+1)\right\rfloor\\\\
&=\left\lfloor\frac{97}4\right\rfloor\\\\
&=24
\end{align*}$$
The value of the summation is $97$, which tells you that there are $97$ factors of $2$ in $100!$: $100!=2^{97}k$, where $k$ is an odd number. $97=4\cdot24+1$, so $100!=2^{4\cdot24+1}k=(2^4)^{24}2k=16^{24}(2k)$, where $2k$ is not a multiple of $16$ (since it’s just $2$ times an odd number). Thus, the base $16$ representation of $2k$ does not end in $0$. Each of the $24$ multiplications of this number by $16$ tacks another $0$ on the end in base $16$, so you end up with $24$ zeroes on the end.
The original sum counts the factors of $2$ in $100!$, but the number of zeroes on the end isn’t the number of factors of $2$: it’s the number of factors of $2^4$, the base. Every four factors of $2$ give you one factor of $2^4$, so you divide by $4$ (and throw away the remainder) to see how many factors of $2^4$ you can build out of your $97$ factors of $2$.
When the base is not a power of a prime, counting the trailing zeroes is a little harder, but it can be done using exactly the same ideas.
</s>