A过去后看了一下别人的解法,发现除了打表还有一种数论的方法。
分析一下阶乘后面的0是怎么出现的呢,当然是2乘5得到的。
我们将1~N先放在一个数组里面。
从数组第一个元素开始,先统计一下N!中因子为5的个数记为count,将其除去,然后再除去count个2。这样一来的话把所有元素乘起来后就不会出现10的倍数了。
当然并不是真正的乘起来,那样的话肯定是要溢出的,因为只关心最后一位数,所以每次乘完后求10的余数即可。
我的做法是打表,因为题目里给了N <= 10000的条件限制,所以可以把1~10000的阶乘的第一个非0的数先算出来放到数组里,然后求哪个输出哪个即可。
Just the Facts
The expression
N
!, read as ``
N
factorial," denotes the product of the first
N
positive integers, where
N
is nonnegative. So, for example,
Just the Facts |
N | N! |
0 | 1 |
1 | 1 |
2 | 2 |
3 | 6 |
4 | 24 |
5 | 120 |
10 | 3628800 |
For this problem, you are to write a program that can compute the last non-zero digit of any factorial for ( ). For example, if your program is asked to compute the last nonzero digit of 5!, your program should produce ``2" because 5! = 120, and 2 is the last nonzero digit of 120.
Input
Input to the program is a series of nonnegative integers not exceeding 10000, each on its own line with no other letters, digits or spaces. For each integer N , you should read the value and compute the last nonzero digit of N !.Output
For each integer input, the program should print exactly one line of output. Each line of output should contain the value N , right-justified in columns 1 through 5 with leading blanks, not leading zeroes. Columns 6 - 9 must contain `` -> " (space hyphen greater space). Column 10 must contain the single last non-zero digit of N !.Sample Input
1 2 26 125 3125 9999
Sample Output
1 -> 1 2 -> 2 26 -> 4 125 -> 8 3125 -> 2 9999 -> 8
Miguel A. Revilla
1998-03-10
打表代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a[40000], b[10000 + 10];
int f(int n);
int main(void)
{
freopen("asdasd.txt", "w", stdout);
a[0] = 1;
b[0] = b[1] = 1;
int i;
for(i = 2; i <= 10000; ++i)
{ //乘以i
int k = i, c = 0;
while(k % 10 == 0)
k /= 10;
for(int j = 0; j < 40000; ++j)
{
int s = a[j] * k + c;
a[j] = s % 10;
c = s / 10;
}
b[i] = f(i);
}
for(i = 0; i <= 10000; ++i)
{
printf("%d,", b[i]);
if(i % 20 == 0)
printf("\n");
}
return 0;
}
//求n!的第一个非0的数
int f(int n)
{
int i;
for(i = 0; i <= 40000; ++i)
if(a[i] != 0)
break;
return a[i];
}
无耻的贴一下AC代码:
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 40000 + 10;
int a[maxn]; //存放阶乘的结果
//存放b[i]阶乘的最后一位非0的数
char b[10000 + 10] = {1,
1,2,6,4,2,2,4,2,8,8,8,6,8,2,8,8,6,8,2,4,
4,8,4,6,4,4,8,4,6,8,8,6,8,2,2,2,4,2,8,2,
2,4,2,8,6,6,2,6,4,2,2,4,2,8,4,4,8,4,6,6,
6,2,6,4,6,6,2,6,4,8,8,6,8,2,4,4,8,4,6,8,
8,6,8,2,2,2,4,2,8,2,2,4,2,8,6,6,2,6,4,4,
4,8,4,6,8,8,6,8,2,2,2,4,2,8,2,2,4,2,8,6,
6,2,6,4,8,8,6,8,2,6,6,2,6,4,4,4,8,4,6,4,
4,8,4,6,2,2,4,2,8,2,2,4,2,8,4,4,8,4,6,6,
6,2,6,4,6,6,2,6,4,8,8,6,8,2,6,6,2,6,4,2,
2,4,2,8,8,8,6,8,2,8,8,6,8,2,4,4,8,4,6,2,
2,4,2,8,4,4,8,4,6,6,6,2,6,4,6,6,2,6,4,8,
8,6,8,2,2,2,4,2,8,4,4,8,4,6,6,6,2,6,4,6,
6,2,6,4,8,8,6,8,2,8,8,6,8,2,6,6,2,6,4,4,
4,8,4,6,4,4,8,4,6,2,2,4,2,8,2,2,4,2,8,4,
4,8,4,6,6,6,2,6,4,6,6,2,6,4,8,8,6,8,2,6,
6,2,6,4,2,2,4,2,8,8,8,6,8,2,8,8,6,8,2,4,
4,8,4,6,2,2,4,2,8,4,4,8,4,6,6,6,2,6,4,6,
6,2,6,4,8,8,6,8,2,2,2,4,2,8,4,4,8,4,6,6,
6,2,6,4,6,6,2,6,4,8,8,6,8,2,2,2,4,2,8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6,6,2,6,4,2,2,4,2,8,4,
4,8,4,6,6,6,2,6,4,6,6,2,6,4,8,8,6,8,2,8,
8,6,8,2,6,6,2,6,4,4,4,8,4,6,4,4,8,4,6,2,
2,4,2,8,4,4,8,4,6,8,8,6,8,2,2,2,4,2,8,2,
2,4,2,8,6,6,2,6,4,8,8,6,8,2,6,6,2,6,4,4,
4,8,4,6,4,4,8,4,6,2,2,4,2,8,8,8,6,8,2,6,
6,2,6,4,4,4,8,4,6,4,4,8,4,6,2,2,4,2,8,8};
char f(int n);
int main(void)
{
#ifdef LOCAL
freopen("568in.txt", "r", stdin);
//freopen("568out.txt", "w", stdout);
#endif
int n;
while(cin >> n)
{
printf("%5d -> %d\n", n, b[n]);
}
return 0;
}
Just the Facts
The expression
N
!, read as ``
N
factorial," denotes the product of the first
N
positive integers, where
N
is nonnegative. So, for example,
Just the Facts |
N | N! |
0 | 1 |
1 | 1 |
2 | 2 |
3 | 6 |
4 | 24 |
5 | 120 |
10 | 3628800 |
For this problem, you are to write a program that can compute the last non-zero digit of any factorial for ( ). For example, if your program is asked to compute the last nonzero digit of 5!, your program should produce ``2" because 5! = 120, and 2 is the last nonzero digit of 120.
Input
Input to the program is a series of nonnegative integers not exceeding 10000, each on its own line with no other letters, digits or spaces. For each integer N , you should read the value and compute the last nonzero digit of N !.Output
For each integer input, the program should print exactly one line of output. Each line of output should contain the value N , right-justified in columns 1 through 5 with leading blanks, not leading zeroes. Columns 6 - 9 must contain `` -> " (space hyphen greater space). Column 10 must contain the single last non-zero digit of N !.Sample Input
1 2 26 125 3125 9999
Sample Output
1 -> 1 2 -> 2 26 -> 4 125 -> 8 3125 -> 2 9999 -> 8
Miguel A. Revilla
1998-03-10