< 返回

# N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39265    Accepted Submission(s): 10930 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in one line, process to the end of file.   Output For each N, output N! in one line.   Sample Input 1 2 3   Sample Output 1 2 6   Author JGShining（极光炫影）
1. #include<iostream>
2. using namespace std;
3. #define MAX 100000
4. int main()
5. {
6.  int i,j,count,n,l,temp;
7.  int a[MAX];
8.  while(scanf("%d",&n)!=EOF)
9.  {
10.   a=1;
11.   count=1;
12.   for(i=1;i<=n;i++)
13.   {
14.    l=0;
15.    for(j=0;j<count;j++)
16.    {
17.     temp=a[j]*i+l;
18.     a[j]=temp%10;
19.     l=temp/10;
20.    }
21.    while(l)
22.    {
23.     a[count++]=l%10;
24.     l/=10;
25.    }
26.   }
27.   for(j=100000;j>0;j--)
28.    if(a[j])
29.     break;
30.    for(i=count-1;i>=0;i--)
31.     printf("%d",a[i]);
32.    printf(" ");
33.  }
34.  return 0;
35. }

/template/Home/DawnNew/PC/Static