69,371
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
const int MAX = 100000;
const int SIZE = 40000/5 + 2;
void Factorial(int *arr, int n);
int main()
{
int arr[SIZE];
int n;
while(cin >> n)
{
memset(arr, 0, sizeof(arr));
Factorial(arr, n);
}
return 0;
}
void Factorial(int *arr, int n)
{
int i, j, pos;
pos = SIZE - 1;
arr[SIZE-1] = 1;
for(i=2;i<=n;i++)
{
for(j=SIZE-1;j>=pos;j--)
arr[j] *= i;
for(j=SIZE-1;j>=pos;j--)
{
if(arr[j] > MAX)
{
if(j == pos)
pos--;
arr[j-1] = arr[j-1] + arr[j]/MAX;
arr[j] %= MAX;
}
}
}
i = 0;
printf("%d", arr[pos++]);
for(;pos<SIZE;pos++)
printf("%05d", arr[pos]);
printf("\n");
}
#include<stdio.h>
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
long v[10000]={1},i=2,a=1,u=0,h=0;
for (i=2;i<=n;i++)
for (u=0,a=0;a<=h;a++)
{
u+=v[a]*i;
v[a]=u%10000;
u/=10000;
if(h==a&&u) h++;
}
printf("%d",v[h]);
while (--h>=0)
printf("%04d",v[h]);
printf("\n");
}
return 0;
}