FCTRL4  Last NonZero Digit of Factorials
Tom is fascinated by big numbers. Most of all he likes factorials. First, he computed N! for some small values of N. But factorials were getting longer and longer very quickly and each of them had a long sequence of zeroes at its end. Since he was unable to consider so many digits in his research and he thought that the research on zeroes would be boring, he decided to focus on the last nonzero digit of factorials.
For example 4!=24 so the last nonzero digit is 4. For N=5 we have 5!=120 and the last nonzero digit 2.
Tom needs to know the last nonzero digit of N! for several specific values of N. Help him please.
Input specification
The input file consists of several positive integers (less than 10^{100}) delimited by whitespace.
Output specification
The output file contains the last nonzero digit of N! for each integer N from the input file. Digits should be delimited by whitespace.
Example
Input file: 1 2 3 4 5 6 7 8 Output file: 1 2 6 4 2 2 4 2
hide comments
prakash1108:
20180109 13:09:32
Last edit: 20180122 16:38:25 

akmal_24:
20160601 23:50:12
It is ridiculous to put time limit. it will check for any value and the higher the value, the more time it takes.


rk:
20150517 12:29:56
is there a O(1) soln bcz people got ac in 0.00 where as i got 0.04 if yes then plz share.


Abhilash:
20141103 14:25:20
do not follow the input specification.


Infinity:
20140912 22:27:21
delimited by white space means ??


John and the cows:
20130813 07:28:28
Last edit: 20140617 09:11:02 

John and the cows:
20130811 07:19:06
Last edit: 20140617 09:11:11 

Shubham Choudhary:
20130202 12:44:36
getting runtime nzec error while using python


strings:
20130104 21:48:20
awesum prblm !! :)


pardeep kumar:
20121231 04:54:29

Added by:  Fudan University Problem Setters 
Date:  20071201 
Time limit:  0.5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 C99 ERL JSRHINO OBJC SQLITE 
Resource:  IPSC 1999 