luogu#P7909. [CSP-J 2021] 分糖果
[CSP-J 2021] 分糖果
Background
The children at Red Sun Kindergarten are starting to share candies.
Problem Description
There are children at Red Sun Kindergarten, and you are one of them. It is guaranteed that .
One day, you find infinitely many candies in the back garden of the kindergarten, and you plan to take some candies back to share with the children.
However, since you are just an ordinary kindergarten child, your strength is limited, and you can carry at most candies back.
But carrying too few is not enough to share, so you must carry at least candies back. It is guaranteed that .
That is, if you take candies, you must ensure that .
If you take candies, you will put these candies into a basket, and require everyone to share candies as follows: as long as there are at least candies in the basket, all children in the kindergarten (including yourself) each take exactly one candy from the basket, until the number of candies in the basket becomes less than . At that point, all remaining candies in the basket belong to you — these candies are your reward for carrying the candies.
As a high-quality kindergarten child, you want the number of candies you get as your reward for carrying the candies ( not the total number of candies you finally get ) to be as large as possible. Therefore, you need to write a program that reads and outputs the maximum number of candies you can obtain as your reward for carrying the candies.
Input Format
One line contains three positive integers , representing the number of children, and the lower and upper bounds on the number of candies.
Output Format
Output one line containing one integer, representing the maximum number of candies you can obtain as your reward for carrying the candies.
7 16 23
6
10 14 18
8
见附件中的 candy/candy3.in。
见附件中的 candy/candy3.ans。
Hint
Sample Explanation #1
Take candies and put them into the basket.
The basket now has candies, so all children each get one candy.
The basket now has candies, so all children each get one candy.
The basket now has candies, so these candies are your reward for carrying the candies.
It is easy to see that the number of candies you get as your reward for carrying the candies cannot exceed (otherwise, the basket would still have at least candies in the end, and everyone would need to take one more candy). Therefore, the answer is .
Sample Explanation #2
It is easy to see that when the number of candies you take satisfies , after all children each take one candy, the remaining candies are always the number of candies as your reward for carrying the candies. Therefore, taking is optimal, and the answer is .
Constraints
| Test Point | |||
|---|---|---|---|
For all testdata, it is guaranteed that .
【Thanks for providing hack data】
wangbinfeng
Translated by ChatGPT 5