使用万进制来做相对来说速度要快些
#include<iostream>
using namespace std;
#include<iomanip>
#define mun 10000
int main()
{
int n, i, j, p, c, place;
while (cin >> n)
{
int a[10000];
a[0] = 1, place = 0 ,c = 0;
for (i = 1; i <= n; i++)
{
for (j = 0; j <= place; j++) //place记录存到了哪一位
{
p = a[j] * i + c;
a[j] = (p%mun);
c = p / mun;
}
while (c > 0)
{
place++;
a[place] =c%mun;
c /= mun;
}
//--------------------------以上与小学学的乘法相似
}
cout<<a[place]; //倒序输出
for (i = place-1; i >= 0; i--)
cout<<setw(4)<<setfill('0')<<a[i];
cout << endl;
}
return 0;
}