NYOJ-28-大数阶乘

大数阶乘

时间限制: 3000 ms  |  内存限制: 65535 KB
难度: 3
描述
我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
输入
输入一个整数m(0<m<=5000)
输出
输出m的阶乘,并在输出结束之后输入一个换行符
样例输入
50
样例输出

30414093201713378043612608166064768844377641568960512000000000000

#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include<queue>
#include<stack>
using namespace std;
int a[10000];
int main()
{
	int  n;
	while(~scanf("%d",&n))
	{
		int digit=1;
		int res,sum;
		int i,j,k;
		a[0]=1;
		for(i=2;i<=n;i++)
		{
			for(res=0,j=1;j<=digit;j++)
			{
				sum=a[j-1]*i+res;
				a[j-1]=sum%10;
				res=sum/10; 
			}
			while(res)
			{
				digit++;
				a[digit-1]=res%10;
				res/=10;
			}
		}
		for(k=digit;k>=1;k--)
		{
			printf("%d",a[k-1]);
		}
		cout<<endl;
	} 
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值