# 74 days to CAT 2015 | Finding the last non-zero digit of n!

Rarely has this concept been come across but it is nevertheless important for CAT or in case of tougher quant-based papers like XAT.

If the number is small in nature, the answer can easily be calculated manually. However, if the number is huge, it becomes difficult to calculate it. The question might seem within reach as there is no big concept involved and so, can eat into precious time. In this article, I will cover how to break down the concept into smaller bits so that it becomes easy to apply for larger numbers as well.

The mechanical approach

For smaller numbers, one can do it manually as we will see:

Find the last non-zero digit of 12!

Now 12! = 12*11*10*9*8*7*6*5*4*3*2*1

As the last non-zero digit is asked, we would simply eliminate the 5s and an equal number of 2s and then multiply only the unit’s place digits to arrive at the solution.

Eliminating two 5s and two 2s, we get: 12*11*2*9*8*7*6*3*2*1

Now, you can simply multiply the numbers successively:

2*1=2 -> 2*2=4 -> 4*9=6 -> 6*8=8 -> 8*7=6 -> 6*6=6 -> 6*3=8 -> 8*2=6

A few derivations you can remember to make it easier to calculate:

Last non-zero digit of 5! = 2

Last non-zero digit of 10! = 8

Last non-zero digit of 15! = 8

Last non-zero digit of 20! = 4

The formula

The basis of the formula is that, the nature of n! is such that it has an unequal number of 2s and 5s with 2s more frequently occuring than 5s. So, the last non-zero digit for any n! where n>1 would be an even number.

Step I: Get the largest integral quotient for n/5 = A

This is very easy and can be done by simple observation. For example: Largest quotient of 136/5 will be 27; that of 2563 will be 512 and so on.

Step II: Find the remainder of n/5 = B

This is again simple and an extension of step I. You can simply find the deviation from the nearest number ending with 5 or 0 and get the remainder. For example: In case of 123/5, the remainder would be 3; that in case of 164/5 would be 4 and so on.

Step III: Find the last non-zero digit of:

2A * A! * B!

Now, the only difficult part here is to find last non-zero digit of A! but then, each iteration decreases the quotient 5 times and so, even in the toughest problems, you would have to do it twice or thrice.

Let’s take a few examples and solve it:

1) Find the last non-zero digit of 26!

A = Quotient of 26/5 = 5

B = Remainder of 26/5 = 1

2A * A! * B!

25 * 5! * 1!

Now, we know by virtue of cyclicity that 25 will end in 2. Also, we know that the last non-zero digit of 5! = 120 is 2. So, it becomes:

Let’s try it for a larger number:

2) Find the last non-zero digit of 100!

In this case, A=20, B=0

220 * 20! * 0!

Now, the trick here is to find the last non-zero digit of 20! using the same technique. In this case, A becomes 4 and B becomes 0. So, the last non-zero digit will be: 24 * 4! * 0! = 6*4 = 4

We will need to plug this back into the original expression:

6 * 4 * 1 will be equal to 4.

So, if one understands the concept well, it is very easy to calculate the last non-zero digit of a number of the form of n!

Let’s cap it off with another, slightly larger example:

3) Find the last non-zero digit of 400!

A=80, B=0

280 * 80! * 0!

6 * 80!                             …(i)

The last non-zero digit of 80! can be found by

216 * 16!

6 * 16!                             …(ii)

The last non-zero digit of 16! can be found by

23 * 3! * 1! = 8*6 = 8

So, plugging it back in expression (ii), we get 6*8 = 8

Plugging back 8 in expression (i), we get 6*8 = 8

Final words

Again, if this question type does appear, it would be with an objective of separating the extremely aware aspirants from the rest. Someone who has not really seen this type would not be able to find a way to deal with it except expanding the entire bit. If the question is some huge number, an under-prepared candidate would probably leave it very early but a pseudo-serious aspirant would stick around and try to find a way losing out on precious time. So, it is a deceptive type and so, should be dealt with extreme caution.

All the best!