nyoj-28 大数阶乘

来源:互联网 发布:广电局禁止网络机顶盒 编辑:程序博客网 时间:2024/06/17 20:31

描述

我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?

输入

输入一个整数m(0

输出

输出m的阶乘,并在输出结束之后输入一个换行符

样例输入

50

样例输出

30414093201713378043612608166064768844377641568960512000000000000

#include <iostream>using namespace std;int main(){   int n;   cin>>n;   int a[100001];   int i,j;   int count=1,next=0,mut;  //mut乘积   next进位 count位数   a[0]=1;   for (i=2;i<=n;i++)   {       for (j=1;j<=count;j++)       {           mut = a[j-1]*i+next;           a[j-1] = mut%10;           next = mut/10;       }       while (next)       {           count++;           a[count-1] = next%10;           next = next/10;       }   }   for (i=count-1;i>=0;i--)    cout<<a[i];    cout<<endl;    return 0;}