1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* 10523 - Very Easy !!!
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&page=show_problem&problem=1464
*
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
*
*
* Status : Accepted
* Runtime: 1.14sec
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;


public class Main {


public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line;
while((line = reader.readLine())!= null){
StringTokenizer token = new StringTokenizer(line);
int n = Integer.parseInt(token.nextToken());
BigInteger a= new BigInteger(token.nextToken());
BigInteger result = new BigInteger("0");
for( int i=1; i<=n; i++){
result = result.add(new BigInteger(i+"").multiply(a.pow(i)));

}
System.out.println(result);

}
}

}