The right-most non-zero digit

It is a common exercise to determine the number of trailing zeros of a factorial . For example, 20 ! = 2 432 902 008 176 64 0 000 20! = 2\; 432\; 902\; 008\; 176\; 64{\color{#20A900}{0}}\; {\color{#20A900}{000}} has 4 trailing zeros (as highlighted in green above).

However, finding the rightmost non-zero digit of a factorial is much harder. For example, the rightmost non-zero digit of 20 ! 20! is 4, as shown above.

Problem: Find the rightmost non-zero digit of 10000 ! 10000! .

2 4 6 8

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Ankit Kumar Jain
Mar 29, 2017

I could't work out any recursive formula or closed form for n n but here is the working process.

Define x N x \in N such that 5 x n < 5 x + 1 5^{x} \leq n < 5^{x + 1} .

a N , a x \forall a \in \mathbb N , a \leq x Find n 5 a ( m o d 10 ) \left\lfloor{\dfrac{n}{5^{a}}}\right\rfloor \pmod{10} , call it b a b_a

Assign the values as follows , call it d a d_a

b a d a 1 1 2 2 3 1 4 4 5 4 6 4 7 3 8 4 9 1 0 1 \begin{array}{l|r} b_a & d_a \\ \hline 1 & 1 \\ \hline 2 & 2 \\ \hline 3&1 \\ \hline 4& 4 \\ \hline 5 &4 \\ \hline 6&4 \\ \hline 7& 3 \\ \hline 8&4 \\ \hline 9&1 \\ \hline 0&1 \end{array}

Evaluate : a = 1 a = x d a \displaystyle\prod_{a = 1}^{a = x} d_a , call the value obtained to be t t

Evaluate the number of trailing zeroes in n ! n! , say m m .

Evaluate y ( m o d 5 ) y \pmod{5} such that 2 m × y t ( m o d 5 ) 2^{m}\times{y} \equiv{t}\pmod{5}

The desired answer is y + 5 y + 5


For the given problem :

x = 5 , t = 4 , m = 2499 , y = 3 8 x = 5 , t = 4 ,m = 2499 , y = 3 \Rightarrow \boxed{8} is the required answer.

I have published a wiki for evaluating one. :)

Tapas Mazumdar - 4 years, 1 month ago

That was great..How did you work that out?

Ankit Kumar Jain - 4 years, 1 month ago

Log in to reply

Just some work. I've added my work in the proof too.

Tapas Mazumdar - 4 years, 1 month ago
Gede Widiastana
Mar 5, 2017

just see and multiply ten numbers from 1 until 10, like as : 1.2.3.4.5.6.7.8.9.10 and the rightmost non-zero is 8

Not quite. You have to watch out for the number of factors of 2 and 5 and account for them accordingly.

Calvin Lin Staff - 4 years, 3 months ago

This is incorrect. By your logic, you would have answered 8 for the number 100 ! 100! as well, when in fact, the answer should be 4.

Pi Han Goh - 4 years, 3 months ago

Log in to reply

Is there a non-tedious solution? I just plugged 10000 ! 1 0 2499 m o d 10 \dfrac{10000!}{10^{2499}} \mod 10 into WolframAlpha.

Jesse Nieminen - 4 years, 3 months ago

Log in to reply

Non-tedious? Not really. But I know a systematic approach. Hint: Find the last non-zero digit of j = 0 9 ( 10 k + j ) \prod_{j=0}^9 (10k + j) , where k k is any arbitrary positive integer. Now what do you observe?

Pi Han Goh - 4 years, 3 months ago

Log in to reply

@Pi Han Goh I don't see a pattern.

Jesse Nieminen - 4 years, 3 months ago

Log in to reply

@Jesse Nieminen I doubt there is an obvious pattern. The answer depends on how which powers of 5 we've hit along the way.

IE 10 ! 10 ! has last digit 8,
20 ! 20 ! has last digit 8 × 8 4 8 \times 8 \equiv 4 ,
30 ! 30 ! "should" have a last digit of 4 × 8 = 32 4 \times 8 = 32 , but because there is an additional multiple of 5 in 25, hence we get 32 × 5 = 160 32 \times 5 = 160 so a last digit of 6 instead.
40 ! 40! has a last digit of 6 × 8 8 6 \times 8 \equiv 8 ,
50 ! 50 ! "should" have a last digit of 8 × 8 64 8 \times 8 \equiv 64 , but because here is an additional multiple of 5 in 50, hence we get 64 × 5 = 320 64 \times 5 = 320 so a last digit of 2 instead.


It is in accurately tracking these multiples of 5 (and hence 2) that it gets tricky to evaluate. IE When we get up to multiples of 125, 625, 3125, etc, the "pattern" changes again.

Calvin Lin Staff - 4 years, 3 months ago

@Jesse Nieminen Ah sorry, my hint is toooo obscure. Here's the answer or click here .

Maybe someone should write a wiki about this. Let me see if I conjure up a clear way of explaining this thing.

Pi Han Goh - 4 years, 3 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...