Alex Rivera | Logout

Last nonzero digit of a factorial

Asked 2012-11-02T13:14:37.630
8

I want to determine the last nonzero digit of a factorial.

I tried to solve it using division: Dividing the number by 10 or multiples thereof.

Ex : 7! = 5040 => 4

So I divide 5040 by 10 and get 4 as result.

But, let us say, we should use the number 7 in the logic instead of value of the factorial (5040).

Please let me know how can I do it?

Edit
Report

1 Answer

1

Lets say D(N) denotes the last non zero digit of factorial, then

D(N)=4*D[N/5]*D(Unit digit of N)[If tens digit of N is odd] D(N)=6*D[N/5]*D(Unit digit of N)[If tens digit of N is even]; Where [N/5] is greatest Integer Function and D(1)=1 D(2)=2 D(3)=6 D(4)=4 D(5)=2 D(6)=2 D(7)=4 D(8)=2 D(9)=8

e.g. D(26)=6*D[26/5]*D(6)=6*D(5)*D(6)=6*2*2=4[D(5) means last non zero digit of 5!=120 which is 2, same for D(6)] D(33)=4*D[33/5]*D(3)=4*D(6)*D(3)=4*2*6=8

Reference : http://quantomania.blogspot.in/2011/08/last-non-zero-digit-of-factorial.html

answered 2013-07-16T16:42:17.480

Your Answer