【Background】
The children of Red-Sun Kindergarten have started to distribute candy!
【Description】
There are n children in kindergarten, and you are one of them. It is guaranteed that n >= 2.
One day you find an "infinite number" of candies in the garden, and you plan to take some candies back and distribute them to the children in the kindergarten.
Since you are just an ordinary kindergarten child, your physical strength is limited, and you can only go back with R lumps at most.
But taking too little is not enough, so you should at least take L candy back. It is guaranteed that n ≤ L ≤ R.
That is, if you take k lumps, then you need to guarantee that L ≤ k ≤ R.
If you take k pieces of candy, you will put the k pieces of candy in the basket and ask everyone to divide the candy according to the following scheme: as long as there are no less than n pieces of candy in the basket, all n children in the kindergarten (including yourself ) take exactly 1 candy from the basket until there are fewer than n candies in the basket. The rest of the candy in the basket is yours, at this point they are your reward for moving the candy.
As a high-quality kindergartener, you want to make the number of candies as a reward for moving candies (instead of the total number of candies you end up getting!) as much as possible!
So you need to write a program that takes n, L, R, and output the maximum number of candies you can get as a reward for moving candies.
Enter a line containing three positive integers n, L, R, representing the number of children, the lower and upper bounds of the number of candies.
【Data range】
guaranteed for all data : 2 ≤ n ≤ L ≤ R ≤ 109
Output a line with an integer representing the maximum number of candies you can get as a reward for moving candies.
7 16 23
6
10 14 18
8
【Example #1 Explanation】
Take k=20 candies and put them in the basket.
The number of candies in the basket is now 20 >= n = 7, so all children get a piece of candy;
The number of candies in the basket now becomes 13 >= n = 7, so all children get a piece of candy;
The number of candies in the basket is now 6 < n = 7, so these 6 candies are your reward for moving candies.
It is easy to find that the number of candies you get as a reward for moving candies cannot exceed 6 pieces (otherwise, the number of candies in the basket is still no less than n at the end, and each child needs to continue to take one piece), so the answer is 6.
ID | User | Problem | Subject | Hit | Post Date |
沒有發現任何「解題報告」 |