这个题目的主要亮点就是高精度
思路:
1.双层嵌套把阶乘+和搞定
2.复习高精度,把 int 全变为高精度表示,这里比较难的就是BigInteger的算术运算
补充:java菜鸟一个,硬解的,不会高级操作
import java.math.BigInteger;
import java.util.Scanner;
/**
* @author qxl~
* @version 1.0
*/
public class P1009 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
BigInteger sum = new BigInteger("0");
BigInteger sum0 = new BigInteger("1");
for (int i = n; i > 0; --i) {
for (int j = 1; j <= i; j++) {
sum0 = sum0.multiply(new BigInteger(String.valueOf(j)));//计算每次!
}
sum = sum.add(sum0);
sum0 = new BigInteger("1"); //刷新sum0进行下一个数计算
}
System.out.println(sum);
}
}