It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.
Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met:
- Each piece of each cake is put on some plate;
- Each plate contains at least one piece of cake;
- No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.
Help Ivan to calculate this number x!
The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.
5 2 3
1
4 7 10
3
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
题意:一共n个盘子,a块第一种蛋糕,b块第二种蛋糕,将蛋糕全部放在盘子里,满足
1.所有蛋糕在盘中 2.所有盘子有蛋糕 3.同一个盘子里不能有同一种蛋糕
求: 盘子里蛋糕数量的最小值的最大值
思路:要想蛋糕的最小值最大,蛋糕应该均分,枚举放第一种蛋糕的盘子数量
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
int maxt=0;
if(a+b==n) maxt=1;
else{
for(int i=1;i<n;i++){
int tem=a/i;
int temp=b/(n-i);
maxt=max(maxt,min(tem,temp));
}
}
printf("%d\n",maxt);
return 0;
}