What is the last nonzero digit at the end of 10!?

246 Views Asked by At

What is the last nonzero digit at the end of $10!$ ? What is the last nonzero digit at the end of $100!$ ? What is the last nonzero digit at the end of $1,000,000!$?

Is there a formula to find out the pattern?

2

There are 2 best solutions below

3
On

I'll demonstrate with $100!$. This is not so much a formula as it is an algorithm that works in $\operatorname{O}(\log(n))$ time for $n!$.

Let $n!!$ denote the product of all odd positive integers less than or equal to $n$. Let $n\tilde{!!}$ denote the product of all odd positive integers less than or equal to $n$ that are not divisible by $5$.

The idea is to extract all powers of $5$ and $2$ from 1000!, and write it as $10^A2^BC$ with $C$ odd and not a multiple of $5$. Then $A$ is the number of trailing zeros. And whatever $2^BC$ is modulo $10$ is the preceding digit. To that end, these two reduction formulas (which you should verify) are useful: $$ \begin{align} n! & = \left\lfloor\frac{n}{2}\right\rfloor! \times n!! \times 2^{ \lfloor\frac{n}{2}\rfloor}\\ n!! & = \left(2\left\lfloor\frac{n+5}{10}\right\rfloor-1\right)!! \times n\tilde{!!} \times 5^{\left\lfloor\frac{n+5}{10}\right\rfloor}\hspace{2pc}n\geq5 \end{align} $$ The first of these is something you may have seen before. The second is the result of trying to find a similar formula that excludes multiples of $5$. A number of the form $n\tilde{!!}$ is even and not diviible by $5$, and is only important to us mod $10$, and its reduction rule is $$n\tilde{!!}\equiv (1\times3\times7\times9)^{\left\lfloor\frac{n}{10}\right\rfloor}\times\epsilon\equiv 9^{\left\lfloor\frac{n}{10}\right\rfloor}\times\epsilon$$ where $\epsilon$ is either $1$, $1(3)\equiv3$, $1(3)(7)\equiv1$ or $1(3)(7)(9)\equiv9$ depending on $n$. We have:

$$ \begin{align} 100! &\equiv 50!\times100!!\times2^{50}\\ 100! &\equiv 50!\times19!!\times100\tilde{!!}\times5^{10}\times2^{50}\\ 100! &\equiv 50!\times19!!\times9^{10}\times5^{10}\times2^{50}\\ 100! &\equiv 50!\times19!!\times5^{10}\times2^{50}\\ 100! &\equiv 50!\times3!!\times19\tilde{!!}\times5^2\times5^{10}\times2^{50}\\ 100! &\equiv 50!\times3!!\times9^{1}(1)(3)(7)(9)\times5^2\times5^{10}\times2^{50}\\ 100! &\equiv 50!\times3(1)\times1\times5^{12}\times2^{50}\\ 100! &\equiv 50!\times3\times5^{12}\times2^{50}\\ 100! &\equiv 25!\times50!!\times2^{25}\times3\times5^{12}\times2^{50}\\ 100! &\equiv 25!\times50!!\times3\times5^{12}\times2^{75}\\ 100! &\equiv 25!\times9!!\times50\tilde{!!}\times5^5\times3\times5^{12}\times2^{75}\\ 100! &\equiv 25!\times9!!\times9^5\times5^5\times3\times5^{12}\times2^{75}\\ 100! &\equiv 25!\times1(3)(5)(7)(9)\times9\times3\times5^{17}\times2^{75}\\ 100! &\equiv 25!\times3\times5^{18}\times2^{75}\\ 100! &\equiv 12!\times25!!\times2^{12}\times3\times5^{18}\times2^{75}\\ 100! &\equiv 12!\times25!!\times3\times5^{18}\times2^{87}\\ 100! &\equiv 12!\times5!!\times25\tilde{!!}\times5^3\times3\times5^{18}\times2^{87}\\ 100! &\equiv 12!\times1(3)(5)\times9^2(1)(3)\times3\times5^{21}\times2^{87}\\ 100! &\equiv 12!\times7\times5^{22}\times2^{87}\\ 100! &\equiv 1(2)(3)(4)(5)(2\cdot3)(7)(8)(9)(2\cdot5)(11)(4\cdot3)\times7\times5^{22}\times2^{87}\\ 100! &\equiv (3)(5)(3)(7)(9)(5)(11)(3)\times7\times5^{22}\times2^{97}\\ 100! &\equiv (3)(3)(7)(9)(11)(3)\times7\times5^{24}\times2^{97}\\ 100! &\equiv 7\times5^{24}\times2^{97}\\ 100! &\equiv 10^{24}\times7\times2^{73}\\ 100! &\equiv 10^{24}\times7\times2^{5\cdot14+3}\\ 100! &\equiv 10^{24}\times7\times2^{14}\times2^3\\ 100! &\equiv 10^{24}\times6\times2^{14}\\ 100! &\equiv 10^{24}\times6\times2^{5\cdot2+4}\\ 100! &\equiv 10^{24}\times6\times2^{2}\times2^4\\ 100! &\equiv 10^{24}\times6\times4\times6\\ 100! &\equiv 10^{24}\times4\times6\\ 100! &\equiv 10^{24}\times4\\ \end{align}$$

So there are 24 zeros, and the preceding digit is a 4. This agrees with a calculation printed in the comments.

1
On

For $10!$:

The last non-zero digit is formed as the product of the digits in the unit places (note that $2\cdot 5$ has to be left out): $$3 \cdot 4 \cdot 6 \cdot 7 \cdot 8 \cdot 9 \equiv 8 \mbox{ mod } 10 \rightarrow \mbox{last non-zero digit: }8$$

For $100!$:

Here the last non-zero digit is formed by $10$ blocks of $(3 \cdot 4 \cdot 6 \cdot 7 \cdot 8 \cdot 9)$:

$$(3 \cdot 4 \cdot 6 \cdot 7 \cdot 8 \cdot 9)^{10} \equiv 8^{10} \equiv 4 \mbox{ mod } 10 \rightarrow \mbox{last non-zero digit: }4$$

For $1000000!$:

Here you have $10^5$ blocks of last digits $(3 \cdot 4 \cdot 6 \cdot 7 \cdot 8 \cdot 9)$:

$$(3 \cdot 4 \cdot 6 \cdot 7 \cdot 8 \cdot 9)^{10^5} \equiv 8^{10 \cdot 10 \cdot 10 \cdot 10 \cdot 10 } \equiv 4^{10 \cdot 10 \cdot 10 \cdot 10} \equiv \ldots \equiv 6 \mbox{ mod } 10 \rightarrow \mbox{last non-zero digit: }6$$