## Last non-zero digit of a factorial

Find a method to calculate the last non-zero digit of , where and .

**Solution:** We have the following formula , where this is proved by removing from terms divisible by .

Since we can obtain the following reccurence , where is the last non-zero digit of and by the integer remainder theorem.

This enables us to calculate the last digit of very fast, descending exponentially at every step to reach small numbers, for which we can easily calculate that digit.

Categories: Number theory, Olympiad, Problem Solving
factorial

Hi,

Thanks for the method. I can use this as long as r is not equal to 0. What will be the answer when r = 0? Or in other terms, what to do when n is a multiple of 5?

Regards.

why is the residue L(r) ? I suspect there’s a problem when r = 1 since 1 != 6 mod 10, even though 1 * 2 = 6 * 7 , 1 * 2 * 3 = 6 * 7 * 8, 1 * 2 * 3 * 4 = 6 * 7 * 8 * 9 mod 10

I don’t understand your point. Please detail a bit what you mean. (there is a small error in your comment: )