码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1042 N!

时间:2014-09-09 12:35:18      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:高精度   mathematics   

就是计算一个数的阶乘。

0<=n<=10000


跟笔算一个样子。每一位用数组去存就好了。

我的挫代码:500+ms

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>

#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define debug puts("==fuck==")
#define acfun std::ios::sync_with_stdio(false)

using namespace std;
int main()
{
    int i,n,len;
    long long j,s,c,a[100001];
    while(~scanf("%d",&n))
    {
        c=0,a[0]=1,len=1;
        for(j=2;j<=n;j++)
        {
            for(i=0;i<len;i++)
            {
                s=c+a[i]*j;
                a[i]=s%1000000000;
                c=s/1000000000;
            }
            while(c>0)
            {
                a[i++]=c%1000000000;
                c/=1000000000;
            }
            len=i;
        }
        printf("%lld",a[len-1]);
        for(i=len-2;i>=0;i--)
            printf("%9.9lld",a[i]);
        printf("\n");
        }
}



HDU 1042 N!

标签:高精度   mathematics   

原文地址:http://blog.csdn.net/dongshimou/article/details/39154131

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!