// http://www.spoj.com/problems/FCTRL2/
#include <iostream>
#include <cstring>
using std::cin;
using std::cout;
using std::endl;
unsigned long long calFactorial(int n){
unsigned long long result=1;
for(unsigned long i=1;i<=n;i++){
result *=i;
}
return result;
}
int main(int argc, char* argv[])
{
int testcasenum;
cin >> testcasenum;
const int MAXLEN = 160;
int result[MAXLEN];
int backup[MAXLEN];
int n;
while (testcasenum-- >0)
{
cin >> n;
memset(result,0,MAXLEN*sizeof(int));
result[0] = 1;
int t = 0;
int reminder = 0;
for (int i = 2; i <=n; i++)
{
int count = i;
memcpy(backup, result, MAXLEN*sizeof(int));
while (count>1)
{
for (int j = 0; j < MAXLEN; j++)
{
t = result[j] + backup[j] + reminder;
if (t>=10)
{
reminder = t/10;
result[j] = t - reminder*10;
}
else
{
result[j] = t;
reminder = 0;
}
}
count--;
}
}
int k = MAXLEN - 1;
while(result[k]==0)
{
k--;
}
while( k>=0 )
{
cout << result[k];
k--;
}
cout<<endl;
}
return 0;
}
Small factorials
最新推荐文章于 2015-05-06 09:12:00 发布