Example 30 (20th Irish Mathematical Olympiad) Find the number of consecutive trailing zeros in 2007! and its last non-zero digit.



Translate the above text into English, please keep the original text's line breaks and format, and output the translation result directly.
Let $F(k)=\left[\frac{2007}{k}\right]\left(k \in \mathbf{N}_{+}\right)$, then the number of times the prime 5 appears in 2007! is $F(5)+F\left(5^{2}\right)+F\left(5^{3}\right)+\cdots$.
Olympic
Math
Problem
in
Number
Theory
Since $5^{5}>2007$, the above formula is
$F(5)+F\left(5^{2}\right)+F\left(5^{3}\right)+F\left(5^{4}\right)$.
After calculation, we know
$F(5)=401, F(25)=80, F(125)=16, F(625)=3$.
Therefore, the number of times 5 appears in 2007! is 500.
Since there are 1003 positive even numbers less than 2007, 2 appears at least 1003 times in 2007!. This means $10^{500} \mid 2007!$, but $10^{501} \nmid 2007!$.
Thus, 2007! ends with 500 consecutive 0s.
Next, we find the last non-zero digit.
First, note the following two facts:
For any integer $k$, we have
$(10 k+1)(10 k+3)(10 k+7)(10 k+9) \equiv-1(\bmod 10)$,
and $\prod_{\substack{i=1 \\ j \neq 5}}^{k}(10 k+i) \equiv 6(\bmod 10)$.
Consider the product of all odd numbers from 1 to 1999 excluding multiples of 5, which can be divided into 200 groups as shown in equation (1). Therefore, these numbers modulo 10 are $(-1)^{200}=1$.
Additionally, $2001 \times 2003 \times 2007 \equiv 1(\bmod 10)$.
On the other hand, as mentioned earlier, $F(5)=401$, meaning there are 401 multiples of 5 (of which 201 are odd) less than or equal to 2007. Therefore, the product of all positive odd numbers less than or equal to 2007 can be expressed as $2007!!=M_{1} \times 5^{201} \times 401!!$, where $M_{1} \equiv 1(\bmod 10)$, and $n!!$ represents the product of all positive odd numbers less than or equal to $n$.

Similarly, $401!!=M_{2} \times 5^{40} \times 79!!$, where $M_{2} \equiv(-1)^{40} \equiv 1(\bmod 10)$;
$79!!=M_{3} \times 5^{8} \times 15!!$,

where $M_{3} \equiv(-1)^{8} \equiv 1(\bmod 10)$;
$15!!=1 \times 3 \times 5 \times 7 \times 9 \times 11 \times 13 \times 15=M_{4} \times 5^{2}$, where $M_{4} \equiv 1(\bmod 10)$.

Therefore, $2007!!=M \times 5^{251}$, where $M \equiv M_{1} M_{2} M_{3} M_{4} \equiv 1(\bmod 10)$.
Next, consider the product of all positive even numbers less than 2007, i.e., $1003!\times 2^{1003}$.
Consider the product of all numbers in 1000! excluding multiples of 5, which can be divided into 100 groups as shown in equation (2). Therefore, these numbers modulo 10 are
$$
6^{100} \equiv 6(\bmod 10) \text {. }
$$
136
Additionally, $1001 \times 1002 \times 1003 \equiv 6(\bmod 10)$.
Since there are 200 multiples of 5 less than 1003, we have
$$
1003!=N_{1} \times 5^{200} \times 200!,
$$

where $N_{1} \equiv 6(\bmod 10)$.
Similarly,
$$
200!=N_{2} \times 5^{40} \times 40!,
$$

where $N_{2} \equiv 6^{20} \equiv 6(\bmod 10)$;
$$
40!=N_{3} \times 5^{8} \times 8!,
$$

where $N_{3} \equiv 6^{4} \equiv 6(\bmod 10)$;
$$
8!=N_{4} \times 5,
$$

where $N_{4} \equiv 2 \times 3 \times 4 \times(-4) \times(-3) \times(-2) \equiv-6(\bmod 10)$.
Therefore, $1003!=N \times 5^{249}$,

where $N \equiv N_{1} N_{2} N_{3} N_{4} \equiv-6(\bmod 10)$.
In summary, we have
$$
2007!=M N \times 5^{500} \times 2^{1003}=M N \times 2^{503} \times 10^{500},
$$

where $M N \equiv-6 \equiv 4(\bmod 10)$.
Since $2^{503} \equiv 8(\bmod 10)$, we have
$M N \times 2^{503} \equiv 4 \times 8 \equiv 2(\bmod 10)$.
Therefore, the last non-zero digit of 2007! is 2.