while True:
	try:
		n, a = input().split()
		n = int(n)
		a = int(a)
		
		resp = 0
		for i in range(1, n + 1):
			resp += i * a ** i
		
		print("{}".format(resp))
	except EOFError:
		break

ec858a1381ae12d0e5132a86669eb2e57c1523b3
<mask token>

while True:
    try:
        n, a = input().split()
        n = int(n)
        a = int(a)
        resp = 0
        for i in range(1, n + 1):
            resp += i * a ** i
        print('{}'.format(resp))
    except EOFError:
        break

while True:
	try:
		n, a = input().split()
		n = int(n)
		a = int(a)
		
		resp = 0
		for i in range(1, n + 1):
			resp += i * a ** i
		
		print("{}".format(resp))
	except EOFError:
		break
