PROGRAM NAME: fact4
INPUT FORMATA single positive integer N no larger than 4,220.
SAMPLE INPUT (file fact4.in)
OUTPUT FORMATA single line containing but a single digit: the right most non-zero digit of N! .
SAMPLE OUTPUT (file fact4.out)
Solution:They only factor could result rear zeros is the product of 2 and 5,(10 could be handled as 2 * 5).
So we count the number of 2s and 5s, obviously 2s are much more than 5s as you can see.
We keep multiply numbers, resulted by removing 2s and 5s, while counting the number of 2s and 5s.
At last, get the final result with 2s and 5s. Check out the code for details.