#P1134. [USACO3.2] 阶乘问题

[USACO3.2] 阶乘问题

Description

Perhaps you already know what a factorial is; the factorial of NN is the product from 11 to NN, for example:

$$12!=1\times 2\times 3\times 4\times 5\times 6\times 7\times 8\times 9\times 10\times 11\times 12=479{,}001{,}600$$

The rightmost non-zero digit of the factorial of 1212 is 66.

Write a program to compute the value of the rightmost non-zero digit of the factorial of N (1N5×107)N\ (1\le N\le5\times 10^7).

Note: There are 24999992499999 trailing zeros in 10,000,000!10{,}000{,}000!.

Input Format

A single line containing a positive integer NN.

Output Format

A single integer, the value of the rightmost non-zero digit.

12
6

Hint

USACO Training Section 3.2.

Translated by ChatGPT 5