HDU 1042 N!

题:http://acm.hdu.edu.cn/showproblem.php?pid=1042

转自:http://www.pan-apps.com/?p=136

 PS:思路分析:

肯定是个大数,而且longlong型的也无法保存,

所以把数字拆开分别保存在数组里

思路如下:

 
#include<iostream>
using namespace std;

int main()
{
    int n,c;
    int i,j,k,count;
    int a[100000];
    while(cin>>n)
    {
        a[0]=1;
        count=0;
        for(i=1;i<=n;i++)
        {
            c=0;
            for(j=0;j<=count;j++)
            {
                a[j]=a[j]*i+c;
                c=a[j]/100000;
                a[j]=a[j]%100000;
            }
            if(c!=0)
            {
                count++;
                a[count]=c;
            }
        }
        cout<<a[count];
        for(k=count-1;k>=0;k--)
            printf("%05d",a[k]);
        cout<<endl;
    }
    return 0;
}

 

 

posted @ 2012-04-21 11:08  川川.aug  阅读(130)  评论(0编辑  收藏  举报