hdu 1042 N!

来源:互联网 发布:mac live photo 编辑 编辑:程序博客网 时间:2024/05/17 03:08

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 53774    Accepted Submission(s): 15212


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
123
 

Sample Output
126
 

#include <iostream>#include <cstring>using namespace std;int main(){    int n=10000;    int a[50000];    while(cin>>n)    {        memset(a,0,sizeof(a));        a[0]=1;        int len=1;        for(int i=1; i<=n; i++)        {            for(int j=0; j<len; j++)            {                a[j]*=i;            }            for(int j=0; j<len; j++)                if(a[j]>9)                {                    a[j+1]+=a[j]/10;                    a[j]%=10;                    if(j==len-1)                    {                        len++;                    }                }        }        for(int i=len-1; i>=0; i--)        {            cout<<a[i];        }        cout<<endl;    }    return 0;    }




0 0