atcoder#ABC203C. [ABC203C] Friends and Travel costs
[ABC203C] Friends and Travel costs
Score : points
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.
2 3
2 1
5 10
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 .
5 1000000000
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
6000000000
Note that the answer may not fit into a -bit integer.
3 2
5 5
2 1
2 2
10
He may have multiple friends in the same village.