Fact
InterviewTime limit1sMemory limit128 MB
For each N up to 10000, find the last non-zero digit of N! and print it with N right-aligned in a field of width 5.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Implementation, Simulation
- Solved
- No attempts yet
Problem
(read " factorial") is the product of the first positive integers, where is a non-negative integer. For example:
N N!
0 1
1 1
2 2
3 6
4 24
5 120
10 3628800
By convention . Given an integer , write a program that finds the last non-zero digit of (the first non-zero digit counting from the right). For example, , so the last non-zero digit is .
Input
The input consists of several lines. Each line contains one non-negative integer with . The input continues until the end of file (EOF).
Output
For each , print one line. First print right-aligned in a field of width , then print " -> " (space, arrow, space), and finally print the last non-zero digit of . In other words, each line has the format %5d -> %d.