-
Title Description:
-
Enter a positive integer n to output the factorial of N.
-
Input:
-
Positive integer N (0<=n<=1000)
-
Output:
-
Input may include multiple sets of data, for each set of input data, the factorial of the output n
-
Sample input:
-
4515
-
Sample output:
-
241201307674368000
-
-
Source:
-
-
2006, Tsinghua University computer Research Life Test real problem
-
#include <iostream> #include <string.h> #include <stdio.h>//code using namespace std with no timeouts; int main () {int N; int num[3001]; while (cin >>n) {int i,j,k; memset (num,0,sizeof (num)); Num[0] = 1; int length = 1; if (N = = 0) {cout << 1 <<endl; Continue } for (i = 1; i<=n; i++) {int over = 0; for (j = 0; J < Length, j + +) {Num[j] = num[j] * i + over; if (Num[j] >=) {over = Num[j]/10; NUM[J] = num[j]% 10; } else over = 0; } while (over! = 0) {int temp = over% 10; Num[length + +] = temp; over = OVER/10; }} for (i = 3000;i >=0; i--) if (num[i]! = 0) break; for (j = i; j >= 0; j--) cout<<num[j]; cout << Endl; } return 0;} /************************************************************** problem:1076 User:carvin language:c++ Resul t:accepted time:1320 Ms Memory:1520 kb****************************************************************/
Factorial of the topic 1076:n