# Talk:Distribution of 0 digits in factorial series

## 8 digits?

Can you please explain the following example?

`Example: for 1 to 6 we have 1!, 2!, 3!, 4!, 5!, 6!, or (1, 2, 3, 24, 120, 720), so (2 zero digits) / (8 total digits) = 0.25.`

Where does the number 8 come from?

--Chunes (talk) 04:46, 10 June 2021 (UTC)

An error, will correct this. --Wherrera (talk) 05:23, 10 June 2021 (UTC)

## number of trailing zeros for factorials

In the Rosetta Code task preamble, it states:

*Because factorial numbers, which quickly become quite large, continue to have another terminal 0 on the right hand side of the number for every 5 increase in the factorial base number, one might think ...*

This is factually true, but understated. In fact, another trailing zero is added for every increase in five, and for every *power of five* as well.

So:

- for every increase in 5, an additional trailing zero is added.
- for every increase in 5
^{2}, an additional trailing zero is added. - for every increase in 5
^{3}, an additional trailing zero is added. - for every increase in 5
^{4}, an additional trailing zero is added. - for every increase in 5
^{5}, an additional trailing zero is added. - •
- •
- •

Here is a simple REXX program than can calculate the number of trailing zeros. -- Gerard Schildberger (talk) 18:14, 10 June 2021 (UTC)
<lang rexx>/*REXX program computes the number of trailing zeros in the factorial for any given N. */
numeric digits 100 /*just in case the user gets ka─razzzy.*/
parse arg N . /*obtain an optional argument from C.L.*/
if N==* | N=="," then N= 1000000 /*Not specified? Then use the default.*/*
z= 0 /*number of trailing zeroes (so far). */
v= 5 /*initialize V to five. */

do while v<=N /*calculate number of trailing zeroes. */ z= z + N % v /*bump Z if multiple power of five.*/ v= v * 5 /*calculate the next power of five. */ end /*while*/ /* [↑] % is REXX's integer division.*/

if z==0 then z= 'no' /*use gooder English for the message. */ say commas(N)'! has ' commas(z) " trailing zeroes." exit z /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang> Here is the output for the number of trailing zeros in the factorial of one million.

- output when using the input of:
`10000000`

1,000,000! has 249,998 trailing zeroes.

True. So the number of terminal zeros actually goes up as the summation over [k from 1 to rounded up(log base 5 of n)] of (n / 5^k), ie n/5 + n/25 + n/125 .... Interesting, though the nonterminal part of n! still dominates the result eventually. --Wherrera (talk) 18:27, 10 June 2021 (UTC)