其中
import java.util.Scanner; import java.math.BigInteger; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { //真的容易超时,还得是大整数相乘啊 public static void process(String n) { if (n.charAt(0) == '1') { System.out.println(1); return ; } BigInteger n1 = new BigInteger(n); BigInteger n2 = new BigInteger(n); BigInteger n3= n2.subtract(new BigInteger("1")); BigInteger res=n1.multiply(n3).subtract(new BigInteger("1")); System.out.println(res); } public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String n = in.next(); process(n); } } }