# Finding the right most non zero digit of a factorial

Suppose,we are asked to find the last non zero digit of 100!, How do we find it?

We know that the number of zeros at the end of 100! is 24.  Our task is to find the leading digit from the right.
Before that, we will see some interesting observations.
100! = 1 × 2 × 3 × 4 × 5 × ........× 99 × 100

Let us write the above format like below
= (5 × 10 × 15 ×......× 95 × 100) × (1 × 2 × 3 × 4 ) × (6 × 7 × 8 × 9) × (11 × 12 × 13 × 14) × (16 × 17 × 18 × 19 ) × ............ × (91 × 92 × 93 × 94) × (96 × 97× 98 × 99)
= (1 × 5) × (2 × 5) × (3 × 5) ×......× (20 × 5) × (1 × 2 × 3 × 4 ) × (6 × 7 × 8 × 9) × (11 × 12 × 13 × 14) × (16 × 17 × 18 × 19 ) × ............ × (91 × 92 × 93 × 94) × (96 × 97× 98 × 99)

By taking 5's common and multiplying the remaining terms,
520 × 20! × (1 × 2 × 3 × 4) × (6 × 7 × 8 × 9) × (11 × 12 × 13 × 14) × (16 × 17 × 18 × 19 ) × ............ × (91 × 92 × 93 × 94) × (96 × 97 × 98 × 99)
We try to find enough number of 2's to multiply with 520 so that it will become zeroes.  So as there are exactly 20 sets of the 4 numbers and we take one "2" from each set.
(1 × 2 × 3 × 4) = 2 × (12)
(6 × 7 × 8 × 9) = 2 × (1512) and so on.
You can see the black terms gives units digits of 2 if we pull of one 2 out of it.
Therefore, unit digit of 100! = ${5^{20}} \times 20! \times 2^{20} \times$ $(2 \times 2 \times ... 20$ times)
= ${5^{20}} \times 20! \times {2^{20}} \times {2^{20}}$
= ${10^{20}} \times 20! \times {2^{20}}$
So non zero units digit of 100! = Unit digit of $20! \times {2^{20}}$

From the above discussion leading non zero digit of 100 ! = $\left[ {\dfrac{{100}}{5}} \right]! \times {2^{[100/5]}} = 20! \times {2^{20}}$

Applying the above logic, the last non zero digit of 20! = $\left[ {\displaystyle\frac{{20}}{5}} \right]! \times {2^{[20/5]}} = 4! \times {2^4}$

So Last non zero digit of 100! = $(20! \times {2^{20}}) = (4! \times {2^4}) \times {2^{20}}$
= 24 x 16 x 6 = 4

The generalized formula to find the non zero digit of N = $\left[ {\dfrac{N}{5}} \right]! \times {2^{\left[ {N/5} \right]}} \times {\left[ {\dfrac{N}{5}} \right]_{{\mathop{\rm Re}\nolimits} m}}!$
Here [ ] denotes greatest integer function.  [3.6] = 3 and rem means remainder when N is divided by 5.

2. How do we proceed If the given number is not divisible by 5 exactly?? For example we have to find the leading  non zero digit of 28!
Solution:
In this case we consider the leading non zero digit upto 25 and manually we multiply the units digits of the remaining 3 terms with the result.
25! = ${5^5} \times 5! \times {2^5} \times {2^5} \Rightarrow {10^5} \times 5! \times {2^5}$
So the unit digit of 25! = 120 x 32 = 4 (We omit the zero)
Now unit digit of 28! = 4 x 26 x 27 x 28 = 4

3. Find the last non zero digit of 2000!
Solution:
We know that Last non zero digit of 2000! = $\left[ {\displaystyle\frac{{2000}}{5}} \right]! \times {2^{(2000/5)}} = (400! \times {2^{400}})$
Again Last non zero digit of 400! = $\left[ {\displaystyle\frac{{400}}{5}} \right]! \times {2^{(400/5)}} = (80! \times {2^{80}})$
Again last non zero digit of 80! = $\left[ {\displaystyle\frac{{80}}{5}} \right]! \times {2^{(80/5)}} = (16! \times {2^{16}})$
Now 16! = $\left[ {\dfrac{{16}}{5}} \right]! \times {2^{\left[ {16/5} \right]}} \times {\left[ {\dfrac{{16}}{5}} \right]_{{\rm{Re}}m}}!$ = $3! \times {2^3} \times 1! = 8$
Now combining the whole discussion last non zero digit of 2000! = ${2^{400}} \times {2^{80}} \times {2^{16}} \times 8$ = 6 x 6 x 6 x 8 = 8

Proof:
Let us consider (10a + 1)(10a + 2)(10a + 3)(10a +4)
This expression is a generalized format of the terms (1 × 2 × 3 × 4 )
For a = 0 we get the first term in the bracket, for a = 1 we get third term in the bracket

By pulling out one 2 and multiplying the remaining terms gives us,
2 × (10a + 1)(5a +1) (10a + 3) (10 a + 4)
2 × (50a2 + 15a + 1)(100a2 +70 a + 12)
2 × (5000a4 + 3500a3 + 600a2 + 1500a3 + 1050a2 + 180a + 100a2 + 70a + 12)
Each term contains zero except the last term. So after pulling one 2 out, unit digit of the remaining expression is 2.

Similarly, (10a + 6)(10a + 7)(10a + 8)(10a + 9)
By pulling out one 2 and multiplying the remaining terms gives us,

2 × (5a + 3)(10a + 7) (10 a + 8) (10 a + 9)
2 × (50a2  + 65a + 21)(100a2  +170 a + 72)
2 × (5000a4 + 8500a3 + 3600a2 + 6500a3 + 11050a2 + 4680a + 2100a2 + 3570a + 1512)
Each term contains zero except the last term. So after pulling one 2 out, unit digit of the remaining expression is 2.