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. Likewise, 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040, so the rightmost non-zero digit of 7! is 4.
PROGRAM NAME: fact4
INPUT FORMAT
A single positive integer N no larger than 4,220.
SAMPLE INPUT (file fact4.in)
7
OUTPUT FORMAT
A single line containing but a single digit: the right most non-zero digit of N! .
SAMPLE OUTPUT (file fact4.out)
4
这题瞎蒙的,开始保留最后两个非零位计算,结果好像在645的地方错了,所以又改了保留三个,就顺利通过了
本文介绍了一个用于计算阶乘尾部非零数字的C++程序设计方法。该程序能够接收一个正整数输入,并输出其阶乘结果中从右往左第一个非零数字。文章提供了一种有效避免大量数值运算导致溢出的方法。
343

被折叠的 条评论
为什么被折叠?



