// 可以计算1~20000的阶乘。在PIII 1.13G CPU上计算20000!约需2.2秒。
#define nRadix 100000
#define MAXSIZE 16000
long in[MAXSIZE]= {0};
void fact(long n)
{
long m_nPrecision = 1;
long temp;
long carry = 0;
int i;
for(i=0; i<MAXSIZE; ++i)
in[i] = 0;
in[0] = 1;
for(i=2; i<=n; ++i)
{
for(long j=0; j<m_nPrecision; j++)
{
temp = in[j]*i+carry;
carry = temp / nRadix;
in[j] = temp - carry * nRadix;
}
temp = carry;
while(temp > 0)
{
carry = temp / nRadix;
in[m_nPrecision++] = temp-carry*nRadix;
temp = carry;
}
}
}
评论