hdu 1042 N!

题意:求n的阶乘,n比较大

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const double inf=1e20;
const int maxn=1e6+10;
const int mod=1e7;

ll a[maxn],m;
ll num0;
void f(ll n){
    for(int i=1;i<=n;i++){
        //printf("%d\n",i);
        ll sum=0;
        ll ii=i;
        while(ii%10==0){
            num0++;
            ii/=10;
        }
        for(int j=0;j<m;j++){
            a[j]*=ii;
            a[j]+=sum;
            sum=a[j]/mod;
            a[j]%=mod;
        }
        if(sum!=0){
            a[m]=sum;
            m++;
        }
    }
}

int main(){
    ll n;
    while(scanf("%lld",&n)!=EOF){
        num0=0;
        m=1;
        a[0]=1;
        f(n);
        for(int i=m-1;i>=0;i--){
            if(i==m-1)printf("%lld",a[i]);
            else printf("%07lld",a[i]);
        }
        for(int i=0;i<num0;i++){
            printf("0");
        }
        printf("\n");
    }
    return 0;
}

 

posted @ 2020-02-27 22:34  wz-Archer  阅读(...)  评论(...编辑  收藏