Strings

Time Limit: 1000ms
Memory Limit: 131072KB
This problem will be judged on HDU. Original ID: 5588
64-bit integer IO format: %I64d      Java class name: Main

Description

Cyy has m kinds of characters,numbered from 1 to m,and the cost of using an i-th character is i.He wants to use these characters to construct N nonempty strings.Every string can not be a prefix of another string.Now he wants to know what the minimum cost is.

Input

There are multiple test cases, no more than 1000 cases.
For each case contains two integers n and m on a line.$(1\leq n\leq {10}^{9},2\leq m \leq {10}^{9})$

Output

For each test case,output minimum cost in a line.

Sample Input

1 2
3 2
5 2
1000 100000

Sample Output

1
7
17
10464

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .