Sunday, May 1, 2016

UVA 10523 - Very Easy !!!

import java.math.BigInteger;
import java.util.Scanner;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int i,a,n;
        BigInteger sum,A;

        while(sc.hasNext())
        {
            n= sc.nextInt();
            a=sc.nextInt();
            sum = new BigInteger("0");
            A = BigInteger.valueOf(a);
            for(i=1; i<=n; i++)
            {
                sum = sum.add(BigInteger.valueOf(i).multiply(A.pow(i)));
            }
            System.out.println(sum);
        }
    }

No comments:

Post a Comment