#include <stdio.h>
// __int64的范围是 [0, 2^64),即0~18446744073709551615(约1800亿亿)
static unsigned __int64 sum_fac(int n);
int main(void)
{
printf("test sum_fac function.\n\n");
for(unsigned int k=0; k<20; k++)
{
printf("k=%dth e sum is: %llu\n",k,sum_fac(k));
}
getchar();
return 0;
}
/* long sum_fac(int n)
作用:求解1!+2!+3!+...+N! ,即阶乘和。
*/
unsigned __int64 sum_fac(int n)
{
if(0 == n)
return 1L;
unsigned __int64 sum = 0;
//Calc
unsigned __int64 tmp = 1;
for(unsigned int i=1;i<=n;i++)
{
tmp *= i;
sum += tmp;
}
return sum;
}