package cn.myAlgorithm;
/**
*
* <p>Title: SumOfFactorial</p>
* <p>Description:求1+2!+3!+...+20!的和</p>
* @author Chill Lyn
* @date 2019年9月22日
*/
class SumOfFactorial {
public static void main(String[] args) {
System.out.println(sumOfFactorial(20));
}
private static long factorial(int num) {
long multi = 1;
for (int i = 1; i <= num; i++) {
multi *= i;
}
return multi;
}
public static long sumOfFactorial(int num) {
long sum = 0;
for (int i = 1; i <= num; i++) {
sum += factorial(i);
}
return sum;
}
}
结果
2561327494111820313