Factorial
Time limit1sMemory limit128 MB
For each n up to 1000, report the last non-zero digit of n!.
- Level
Medium4 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
denotes the factorial of an integer , the product of all integers from to . Factorials grow extremely quickly: exceeds the range of a 32-bit integer on most computers, and exceeds the range of most floating-point variables. We want to find the rightmost non-zero digit of . For example, , so the rightmost non-zero digit of is . Likewise, , so the rightmost non-zero digit of is .
Input
The first line contains the number of test cases (). Each of the following lines contains a single integer ().
Output
For each test case, print the rightmost non-zero digit of on its own line.