HDU - 1042 - N!(高精度)

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
typedef long long LL;
LL ans[10000];
const LL mod = 1e9;
int main()
{
    int n, size;
    while(scanf("%d",&n)!=EOF){
        ans[1] = size = 1;
        for(int i=1;i<=n;i++){
            ans[size+1] = 0;
            for(int j=1;j<=size;j++) ans[j] *= i;
            for(int j=1;j<=size;j++){
                if(ans[j]>=mod){
                    ans[j+1] += ans[j]/mod;
                    ans[j] %= mod;
                }
            }
            if(ans[size+1]>0) size++;
        }
        printf("%lld",ans[size]);
        for(int i=size-1;i>=1;i--) printf("%09lld",ans[i]);
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/w326159487/article/details/79864875