Connection Status:
Competition Arena > KidsInAYard
TCO19 SRM 746 · 2019-01-09 · by misof · Brute Force
Class Name: KidsInAYard
Return Type: int
Method Name: howMany
Arg Types: (int, int, int)
Problem Statement

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.

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
0)
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.

1)
0
2
2
Returns: 2
2)
1
0
3
Returns: 3
3)
0
1
4
Returns: 4
4)
1
2
0
Returns: 5
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.)

29)
0
0
0
Returns: 30

Note that the number of kids must be positive.

Submissions are judged against all 30 archived test cases, of which 7 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class KidsInAYard with a public method int howMany(int r2, int r3, int r5) · 30 test cases · 2 s / 256 MB per case

Submitting as anonymous