Saturday, September 29, 2018

UVa problem solution 10523 - Very Easy !!!

problem link:

Discuss: there is many approach to solve this problem. i using java language since it has BigInteger class. if you know java and function of BigInteger then it's very naive problem to you. don't forget to name your class Main(capital M) this is for UVa.

try yourself, before see the code





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

public Main {

public static void main(String[] args) {
Scanner in=new Scanner (System.in);
while(in.hasNext()) {
int i,j,n,a;
BigInteger sum=BigInteger.ZERO;
n=in.nextInt();
a=in.nextInt();
BigInteger A=BigInteger.valueOf(a);
BigInteger PA,mul;
for(i=1; i<=n; i++) {
PA=A.pow(i);
mul=PA.multiply(BigInteger.valueOf(i));
sum=sum.add(mul);
}
System.out.println(sum);
}


}

}

No comments:

Post a Comment