(数组应用二:高精度运算4.2.2)UVA 10523 VERY EASY !!! (大数累加)

package com.njupt.acm;

import java.math.BigInteger;
import java.util.Scanner;

public class UVA_10523 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(scanner.hasNext()){
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			
			int i;
			BigInteger sum = new BigInteger("0");
			for(i = 1 ; i <= n ; ++i){
				sum = sum.add(new BigInteger(i +"").multiply(new BigInteger(a+"").pow(i)));
			}
			
			System.out.println(sum);
		}
	}
}

你可能感兴趣的:((数组应用二:高精度运算4.2.2)UVA 10523 VERY EASY !!! (大数累加))