1) I use RPF here for “Relatively Prime to Five.” 2) N > 1 3) For all divisions “/”, only quotient is considered. Fractions ignored. *************************************** Solution: *************************************** Let P_1 = N/5, (Only quotient) P_2 = N/(5^2) P_3 = N/(5^3) and so on till .... ……. P_k = N/(5^k) Beyond (5^k), higher powers of 5 gives quotient 0. Let summation of Pi = P Notice that {N!/(10)^P}(Mod 10) is what we need. ***************************************** Let RPF(q) indicate the product of first q natural numbers, which are relatively prime to 5. Let RemRPF(q) indicate the reminder(when divided by 10) of first q natural numbers, which are relatively prime to 5. Example RPF(11) = (1*2*3*4*6*7*8*9)*(11*12*13) ---------------------------------------------------------------------------(1) It can be easily observed that RemRPF(q) is repetitive from RemRPF(9) onwards. For example { RemRPF(9) , RemRPF(10)….. RemRPF(16)} = { RemRPF(17) , RemRPF(18)….. RemRPF(24)} = {6,2,6,4,4,8,4,6} ----------------------------------------------------------------------------------------------------------------------(2) Since it is repetitive, from (2), it can be seen that [RemRPF(q)] = [RemRPF(q(Mod 8))] -----------------------------------------------------------------------------(3) Note that in (3), treat RemRPF(1) = 6, instead of 1. And also RemRPF(0) = RemRPF(8). ***************************************** 2*2*2*2*2*2*2*2 The corresponding reminders at each stage of the above multiplication, are {2,4,8,6,2,4,8,6} And it can be seen that this reminder pattern {2,4,8,6} repeats. ----------------------------------------------------------------(4) ******************************************* Let N(i) = RPF(4*P_{i+1} + ((N( Mod 5^{i+1}))/(5^i)} Note that (N!/10^P)(Mod 10) = [{\prod_{i=0}^k[N(i) ]}/2^P] (mod 10) = [[\prod_{i=0}^k{RPF(4*P_{i+1} + ((N( Mod 5^{i+1}))/(5^i)) }]/[2^P]](mod 10)---------------------------------(5) Applying (2), (3) & (4) to (5) we get (N!/10^P)(Mod 10) = [[\prod_{i=0}^k{RemRPF[RPF((4*P_{i+1} + ((N( Mod 5^{i+1}))/(5^i)))(mod 8) }]/[2^{P(mod 4)}]](mod 10)---------------------------------(6) The expression in equation (6) can be easily calculated manually. In the numerator, each RemRPF[RPF((4*P_{i+1} + ((N( Mod 5^{i+1}))/(5^i)))(mod 8) } can be reduced to a single digit number. ******************************************************** Example : N = 93 i = 0 = RemRPF[RPF((4*18 + ((93( Mod 5))/(5^{0})))(mod 8) } = RemRPF[RPF((4*18 + 3)(mod 8)) } = RemRPF[RPF(3)] = 6 &&&&&&&&&&&&&&& I = 1 = RemRPF[RPF((4*3 + ((93( Mod 25))/(5)))(mod 8) } = RemRPF[RPF((4*3 + 3)(mod 8) } = RemRPF[RPF(7)] = 4 &&&&&&&&&&&&&&&& I = 2 = RemRPF[RPF((4*0 + ((93( Mod 125))/(25)))(mod 8) } = RemRPF[RPF((4*0 + 3)(mod 8) } = RemRPF[RPF(3)] = 6 &&&&&&&&&&&&&&&&&& 2^P (mod 10) = 2^21 (mod 10) = 2^1 (mod 10) = 2 The answer for 93! = ((6*4*6)/2)(mod 10) = 2