Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class Main {
- public static void main(String[]args)
- {
- BigInteger sum,bi,bi1,bi2,bi3;
- int i,N,A;
- Scanner sc = new Scanner(System.in);
- while(sc.hasNext())
- {
- N = sc.nextInt();
- A = sc.nextInt();
- sum = BigInteger.ZERO;
- for( i=1 ; i<=N ; i++)
- {
- bi = BigInteger.valueOf(i);
- bi1 = BigInteger.valueOf(A);
- bi2 = bi1.pow(i);
- bi3 = bi2.multiply(bi);
- sum = sum.add(bi3);
- }
- System.out.println(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment