1057 N的阶乘
基准时间限制:1 秒 空间限制:131072 KB 分值: 0
难度:基础题
输入N求N的阶乘的准确值。
Input
输入N(1 <= N <= 10000)
Output
输出N的阶乘
Input示例
5
Output示例
120
<pre name="code" class="cpp">#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
#define N 1000005
#define mod 100000000000000
ll ans[10000000];
int main()
{
ll n;
scanf("%I64d",&n);
ll i,j;
ll l=0;
ans[0]=1;
for(i=1; i<=n; i+=1)
{
ll c=0;
for(j=0; j<=l; j+=1)
{
ll t=ans[j]*i+c;
ans[j]=t%mod;
c=t/mod;
}
if(c!=0)
{
ans[++l]=c;
}
}
printf("%I64d",ans[l]);
for(i=l-1; i>=0; i-=1)
{
printf("%0.14I64d",ans[i]);
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-1305746.html