Department of Math and Computer Science
Problems of the Month 1995
|
Problem for 1995 November |
What is the last non-zero digit in the decimal representation of 1,000,000! ?
Remark: Using Stirling's famous approximation one can show that
|
1,000,000! » 8.26399×105,565,708, |
|
and, using a standard result in number theory, one can show easily that
the decimal representation of 1,000,000! ends with 249,998 zeros.
Therefore 1,000,000! is a number of 5,565,709 decimal digits, and if
written out has the following appearance:
|
8,263,¼{ 5,315,706 more digits}¼,x00,000,¼{ 249,990 more zeros}¼,000 |
|
where x is a non-zero digit.
What is x?
The proposer used a computer to solve this problem, and you are permitted to do
so also; the proposer hopes that someone finds a better solution.
Notation: N={1,2,3,¼}; W={0}ÈN; P={2,3,5,7,11,13,¼}, the set of primes.
For each prime p let np:N® W as follows-
|
n Î NÞ n=2n2(n)×3n3(n)×5n5(n)×¼ = |
Õ
p Î P
|
pnp(n); |
|
i.e., np(n) is the number of occurrences of the prime p in the
factorization of n as a product of primes.
Clearly the decimal representation of n! ends with n5(n!) zeros, and
|
n Î WÞ |
n!
10n5(n!)
|
=2n2(n!)-n5(n!)×3n3(n!)× |
Õ
p Î P, 5 < p
|
pnp(n!). |
|
Next one computes at once that if p º p0 (mod 10) and 0 < k, then
pk º the value shown in the following table (mod 10). (k is taken modulo 4.)
-
|
|
|
|
|
| | | | | | | | | | |
| p0 | | k º 0 | | k º 1 | |
k º 2 | | k º 3 | |
| | | | | | | | | | |
|
| 0 | | 0 | | 0 | | 0 | | 0 | |
| | | | | | | | | | |
|
| 1 | | 1 | | 1 | | 1 | | 1 | |
| | | | | | | | | | |
|
| 2 | | 6 | | 2 | | 4 | | 8 | |
| | | | | | | | | | |
|
| 3 | | 1 | | 3 | | 9 | | 7 | |
| | | | | | | | | | |
|
| 4 | | 6 | | 4 | | 6 | | 4 | |
| | | | | | | | | | |
|
| 5 | | 5 | | 5 | | 5 | | 5 | |
| | | | | | | | | | |
|
| 6 | | 6 | | 6 | | 6 | | 6 | |
| | | | | | | | | | |
|
| 7 | | 1 | | 7 | | 9 | | 3 | |
| | | | | | | | | | |
|
| 8 | | 6 | | 8 | | 4 | | 2 | |
| | | | | | | | | | |
|
| 9 | | 1 | | 9 | | 1 | | 9 | |
| | | | | | | | | | |
|
|
|
|
|
Also as is well-known and easily proved: n Î W & p Î PÞ np(n!)=åi=1¥
ë[ n/(pi)]
û.
This suggests the following method, which is easily implemented as a computer
program, for computing the right-most non-zero digit in the decimal
representation of n!-
-
0.
-
Put x=2n2(n!)-n5(n!)×3n3(n!) mod 10; one uses
the information in the table above to do this easily.
-
1.
- For each prime p such that 5 < p £ n one determines
np(n!) and its congruence class mod 10. Again referring to the table
above one multiplies x by the appropriate value, and of course reduces this
to its value modulo 10.
-
2.
- After accumulating this product (mod 10) for all primes £ n
the value of x is the right-most non-zero digit in the decimal
representation of n!.
The proposer implemented this method in an assembly language program which, for
the case n=1,000,000, ran in about 68 seconds on a 16 MHz 80386-based
computer, and in about 8 seconds on a 90 MHz Pentium-based computer; and
produced the result x=4.
Also solved by Professor Bill Nico and Devang Vora. One incorrect solution was
received.
File translated from
TEX
by
TTH,
version 3.01.
On 11 Oct 2001, 06:52.