import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args) {
Scanner cin = new Scanner(new BufferedInputStream(System.in));
while(cin.hasNext()){
int n = cin.nextInt();
BigInteger a = cin.nextBigInteger();
BigInteger sum = BigInteger.ZERO;
for(int i = 1; i <= n; ++i){
BigInteger t = BigInteger.valueOf(i);
sum = sum.add(t.multiply(a.pow(i)));
}
System.out.println(sum);
}
}
}