Problem Statement
Some kids were playing in the yard. You noticed the following:
- When they formed groups of two, r2 kids were left without a group.
- When they formed groups of three, r3 kids were left without a group.
- When they formed groups of five, r5 kids were left without a group.
Find and return the smallest (positive) number of kids that could have played in the yard.
Definition
- Class:
- KidsInAYard
- Method:
- howMany
- Parameters:
- int, int, int
- Returns:
- int
- Method signature:
- int howMany(int r2, int r3, int r5)
- (be sure your method is public)
Notes
- A solution always exists.
Constraints
- r2 will be between 0 and 1, inclusive.
- r3 will be between 0 and 2, inclusive.
- r5 will be between 0 and 4, inclusive.
Examples
1
1
1
Returns: 1
There was a single kid. Regardless of the group size, no groups were formed and the kid was the one left over.
0
2
2
Returns: 2
1
0
3
Returns: 3
0
1
4
Returns: 4
1
2
0
Returns: 5
0
0
1
Returns: 6
1
1
2
Returns: 7
0
2
3
Returns: 8
1
0
4
Returns: 9
Nine kids can form three groups of three. If they form pairs, one kid will be left over. Finally, they can form one group of five and have four kids left over. We can easily verify that nine kids is the smallest solution in this case. (There are other solutions, for example, 519 kids, but you have to return the smallest solution.)
0
1
0
Returns: 10
1
2
1
Returns: 11
0
0
2
Returns: 12
1
1
3
Returns: 13
0
2
4
Returns: 14
1
0
0
Returns: 15
0
1
1
Returns: 16
1
2
2
Returns: 17
0
0
3
Returns: 18
1
1
4
Returns: 19
0
2
0
Returns: 20
1
0
1
Returns: 21
0
1
2
Returns: 22
1
2
3
Returns: 23
0
0
4
Returns: 24
1
1
0
Returns: 25
0
2
1
Returns: 26
1
0
2
Returns: 27
0
1
3
Returns: 28
1
2
4
Returns: 29
0
0
0
Returns: 30
Note that the number of kids must be positive.