UVA – 10523 – Very Easy !!!

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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int N = in.nextInt();
			int A = in.nextInt();
			BigInteger ans = BigInteger.ZERO;
			ArrayList<BigInteger> powers = new ArrayList<BigInteger>(N);
			powers.add(BigInteger.ONE);

			for (int i = 1; i <= N; i++) {
				BigInteger S_i = powers.get(i - 1).multiply(new BigInteger("" + A));
				powers.add(S_i);
				ans = ans.add(S_i.multiply(new BigInteger(i + "")));
			}

			System.out.println(ans);
		}
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: