2831. Factorials

单点时限: 2.0 sec

内存限制: 256 MB

The factorial of an integer n, written n!, is the product of all the integers from 1 through n inclusive. The factorial quickly becomes very large: 13! is too large to store in a 32-bit integer on most computers, and 70! is too large for most floating-point variables. Your task is to find the rightmost non-zero digit of n!. For example, 5! = 1 * 2 * 3 * 4 * 5 = 120, so the rightmost non-zero digit of 5! is 2. Also, 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040, so the rightmost non-zero digit of 7! is 4.

输入格式

The first line of the input contains the number of test case (<15). The single line which represents each test case contains an integer n, between 1 and 1000 inclusive. . ..

输出格式

Print to the output the rightmost non-zero digit of n!

样例

Input
1
5
Output
2

51 人解决,64 人已尝试。

60 份提交通过,共有 154 份提交。

3.8 EMB 奖励。

创建: 13 年,7 月前.

修改: 6 年,8 月前.

最后提交: 9 月,1 周前.

来源: Ukrainian

题目标签