P2529 [SHOI2001] Passing the Flower

Description

HC (Happy Child) and classmates often play a game called "passing the flower" in the classroom. The rule is that the child who gets the flower for the $n$-th time must say the last non-zero digit of $n!$. The game proceeds in cycles, and anyone who answers incorrectly has to sing a song as a penalty. After a few rounds, HC believed that one could simply multiply the previous child's number by $n$ and then say the last non-zero digit of the resulting number. Unfortunately, when it was HC's turn at $n = 15$, HC answered $3$ and was penalized, while the correct answer should have been $8$. HC does not want this to happen again, so you are asked to write a program that computes the last non-zero digit of $n!$.

Input Format

There are $5$ lines of input. The $i$-th ($1 \le i \le 5$) line contains an $n$ ($1 \le n \le 10^{100}$).

Output Format

Output $5$ lines. The $i$-th line should be the last non-zero digit of the factorial of the $n$ on the $i$-th input line.

Explanation/Hint

Translated by ChatGPT 5