求 1! + 2! + 3! + ... + n!
long long unsigned factorial(long long unsigned num)
{
return num < 2LL? 1LL : (factorial(num - 1LL) * num);
}
long long unsigned factoricalSum(long long unsigned num)
{
return num < 2LL? 1LL : factoricalSum(num - 1LL) + factorial(num);
}
long long unsigned factoricalSum(long long unsigned num)
{
function<long long unsigned(long long unsigned)> factorial;
factorial = [&factorial](decltype(num) n){return n < 2LL? 1LL : (factorial(n - 1LL) * n);};
return num < 2LL? 1LL : factoricalSum(num - 1LL) + factorial(num);
}
原创 禁转