原题链接 来自洛谷https://www.luogu.com.cn/problem/P1009#submit
#include <bits/stdc++.h>
using namespace std;
int sum[101] = {0}; // 阶乘和
int ans[101] = {0}; // 阶乘
int main()
{
int i, j, t;
int n;
scanf("%d", &n);
ans[100] = 1; t = 0;
for (i = 1; i <= n; i++)
{
// 乘i
//printf ("i_%d\n", i);
for (j = 100; j > 0; j--)
{
t += ans[j ] * i;
ans[j] = t % 10;
t /= 10;
}
/*printf ("ans ");
for (j = 0; !ans[j]; j++);
for (; j <= 100; j++)
printf ("%d", ans[j]);
printf ("\n");*/
// 加到sum里
for (j = 100; j > 0; j--)
{
sum[j] += ans[j];
sum[j-1] += sum[j] / 10;
sum[j] %= 10;
}
/*
printf ("sum ");
for (j = 0; !sum[j]; j++);
for (; j <= 100; j++)
printf ("%d", sum[j]);
printf ("\n");*/
}
for (i = 0; !sum[i] && i < 100; i++);
for (; i <= 100; i++)
printf ("%d", sum[i]);
return 0;
}