#include<iostream>
#include<vector>
#include<algorithm>
#include<ctime>
using namespace std;
#define D 10000
clock_t stop,start;
int main()
{
int i,j,c,p,n;
while(cin>>n){
start=clock();
vector<vector<int> >v(10000);
v[1].push_back(1),v[2].push_back(2);
for(i=3;i<n+1;i++)
{
c=0;
reverse(v[i-1].begin(), v[i-1].end());
for (j = 0; j < v[i-1].size(); j++)
{
p = v[i-1][j] *i + c;
v[i].push_back(p % D);
c = p/D;
}
while (c>0)
{
v[i].push_back(c %D);
c /=D;
}
reverse(v[i].begin(), v[i].end());
}
stop=clock();
for(i=0;i<v[n].size();i++)
cout<<v[n][i];
cout<<endl;
cout<<"结果位数为:"<<v[n].size()<<endl;
cout<<"所用时间为:"<<double(stop-start)/1000<<"秒"<<endl;
}
return 0;
}
原文:http://www.cnblogs.com/td15980891505/p/4336234.html