内存限制:64MB
时间限制:3000ms
Special Judge: No
accepted:19
submit:39
题目描述:
输入描述:
输入一个整数m(0<m<=5000)
输出描述:
输出m的阶乘,并在输出结束之后输入一个换行符
样例输入:
50
样例输出:
30414093201713378043612608166064768844377641568960512000000000000
提示:
1 for(int i = 1; i <= m; ++ i) // 其中数组A存的即为大数相乘的结果 2 { 3 int b = 0; // 处理余数问题 4 for(int j = 1; j <= len; ++ j) 5 { 6 int t = b + i*A[j]; 7 A[j] = t % 10; 8 b = t / 10; 9 if(b > 0 && j == len) len ++; 10 } 11 }
C/C++代码实现(AC):
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <cmath> 6 #include <stack> 7 #include <map> 8 #include <queue> 9 10 using namespace std; 11 const int MAXN = 100005; 12 13 int main() 14 { 15 int m, A[MAXN] = {1, 1}, len = 1; 16 scanf("%d", &m); 17 18 for(int i = 1; i <= m; ++ i) 19 { 20 int b = 0; 21 for(int j = 1; j <= len; ++ j) 22 { 23 int t = i * A[j] + b; 24 A[j] = t % 10; 25 b = t / 10; 26 if (j == len && b > 0) ++len; 27 } 28 } 29 30 for(int i = len; i >= 1; -- i) 31 printf("%d", A[i]); 32 printf("\n"); 33 return 0; 34 }