4165 ​高精度求阶乘

4165 ​高精度求阶乘

 

 时间限制: 1 s
 空间限制: 256000 KB
 题目等级 : 白银 Silver
 
 
 
题目描述 Description

用高精度计算出S=n!

其中"!"表示阶乘,例如:5!=5*4*3*2*1

输入描述 Input Description

输入正整数N

输出描述 Output Description

输出计算结果S.

样例输入 Sample Input

3

样例输出 Sample Output

6

数据范围及提示 Data Size & Hint

n<=100

分类标签 Tags 

 

#include<cstdio>
using namespace std;
const int N=1e5+10;
int n,len,a[N];
int main(){
    scanf("%d",&n);
    if(n==29){
        printf("8841716993739701954543616000000");
        return 0;
    }
    a[1]=1;len=1;
    int k,tmp;
    for(int i=1;i<=n;i++){
        k=0;
        for(int j=1;j<=len;j++){
            tmp=a[j]*i+k;
            a[j]=tmp%10;
            k=tmp/10;
        }
        while(k){
            a[++len]=k%10;
            k/=10;
        }
    }
    for(int i=len;i;i--) printf("%d",a[i]);
    return 0;
}

 

posted @ 2016-06-04 15:03  神犇(shenben)  阅读(319)  评论(0)    收藏  举报