题目大意:给你一个公式,直接按照式子计算就可以了,要用到大数。
1 import java.io.*; 2 import java.util.*; 3 import java.math.*; 4 5 class Main 6 { 7 public static void main(String[] args) 8 { 9 Scanner sc = new Scanner(System.in); 10 while (sc.hasNextInt()) 11 { 12 int n = sc.nextInt(); 13 BigInteger a = BigInteger.valueOf(sc.nextInt()); 14 BigInteger sum = BigInteger.valueOf(0); 15 BigInteger t = BigInteger.valueOf(1); 16 for (int i = 1; i <= n; i++) 17 { 18 t = t.multiply(a); 19 BigInteger tmp = t.multiply(BigInteger.valueOf(i)); 20 sum = sum.add(tmp); 21 } 22 System.out.println(sum); 23 } 24 } 25 }