Step 1. Count the Trailing Zeros
Trailing zeros come from factors of 10 in n!. Since 10 = 2 × 5, and there are always more factors of 2 than 5, the number of trailing zeros is determined by the number of factors of 5.
For 96!:
⌊96/5⌋ = 19
⌊96/25⌋ = 3
⌊96/125⌋ = 0
Thus, the total number of factors of 5 (and hence factors of 10) is 19 + 3 = 22. In other words, 96! ends in 22 zeros. To find the last nonzero digit, we “remove” these factors of 10 from the product.
Step 2. Use the Recursive Formula
A recursive formula for the last nonzero digit of n!, denoted d(n), is:
d(n) = { (last nonzero digit of n! computed directly) if n < 5,
d(⌊n/5⌋) × f(n mod 5) × 2(⌊n/5⌋) (mod 10) if n ≥ 5 }
Here, the function f(r) gives the last nonzero digit of r! for 0 ≤ r < 5. Specifically, we have:
f(0) = 1, f(1) = 1, f(2) = 2, f(3) = 6, f(4) = 4.
Step 3. Compute d(96)
Write 96 in the form 96 = 5q + r. Here:
q = ⌊96/5⌋ = 19
r = 96 mod 5 = 1
Thus, the formula gives: d(96) = d(19) × f(1) × 2(19) (mod 10).
Since f(1) = 1, this simplifies to: d(96) = d(19) × 2(19) (mod 10).
Step 4. Compute d(19)
Now, write 19 = 5q′ + r′. Here:
q′ = ⌊19/5⌋ = 3
r′ = 19 mod 5 = 4
Thus: d(19) = d(3) × f(4) × 2(3) (mod 10).
For n = 3 (which is less than 5), we directly have:
d(3) = f(3) = 6.
Also, f(4) = 4 and 2(3) is represented as 2³ = 8. Therefore:
d(19) = 6 × 4 × 8 = 192.
Taking this modulo 10: 192 (mod 10) = 2.
Step 5. Finish Calculating d(96)
as : d(96) = d(19) × 2(19) (mod 10).
We found d(19) = 2, so: d(96) = 2 × 2(19) (mod 10),
Now, compute 2¹⁹ (mod 10). Notice that powers of 2 modulo 10 cycle every 4:
2¹ = 2,
2² = 4,
2³ = 8,
2⁴ = 16 ≡ 6 (mod 10),
the cycle repeats.
Since 19 mod 4 = 3, we have:
2¹⁹ ≡ 2³ ≡ 8 (mod 10).
Thus: d(96) = 2 × 8 = 16 (mod 10).
Taking modulo 10 gives: 16 (mod 10) = 6.
The last nonzero digit of 96! is 6.