求 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);
}

 

原创  禁转

posted @ 2015-07-17 00:20  wu_overflow  阅读(214)  评论(0编辑  收藏  举报