numbers = list(open('input.txt','r').read().strip().split()) outfile = open('output.txt','w') n = int(numbers[0]) a = int(numbers[1]) s = 0 d = 1 for x in range(1,n+1): d *= a s += x*d outfile.write('%s\n' % (s))