#abc203c. [abc203_c]Friends and Travel costs
[abc203_c]Friends and Travel costs
Problem Statement
There are villages, labeled with numbers , , , .
For every integer between and (inclusive), you can pay yen (the currency) in Village to get to Village . There is no other way to travel between villages.
Taro has yen and is in Village now. He will try to get to a village labeled with as large a number as possible.
He has friends. The -th friend, who is in Village , will give Taro yen when he reaches Village .
Find the number with which the last village he will reach is labeled.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2 3
2 1
5 10
Sample Output 1
4
Takahashi will travel as follows:
- Go from Village to Village , for yen. Now he has yen.
- Go from Village to Village , for yen. Now he has yen.
- Get yen from the -st friend in Village . Now he has yen.
- Go from Village to Village , for yen. Now he has yen.
- Go from Village to Village , for yen. Now he has yen, and he has no friends in this village, so his journey ends here.
Thus, we should print .
Sample Input 2
5 1000000000
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
Sample Output 2
6000000000
Note that the answer may not fit into a -bit integer.
Sample Input 3
3 2
5 5
2 1
2 2
Sample Output 3
10
He may have multiple friends in the same village.