PEG Test - Halloween 2014
Alex and Ben have found a peculiar street in their neighborhood this Halloween night.
On this street, houses on the left side of the street are numbered with
consecutive prime numbers starting from
Index: 1 2 3 4 5 6 7 8 9
Left House #: 2 3 5 7 11 13 17 19 23
Right House #: 4 6 8 9 10 12 14 15 16
Alex will trick or treat on the left side, and Ben will trick or treat
from the right side. They will begin trick-or-treating at a house with
the same index, and can cover a range of
Determine the index of the house that Alex and Ben should start at such
that, after Alex pays
Input Specification
There will be one line of input containing two integers
Output Specification
Output a single integer, the index of the house that Alex and Ben should start at such that they finish with the minimum difference in candy amount. If multiple solutions exist, print the smallest one.
Sample Input 1
0 5
Sample Output 1
3
Explanation 1
Alex does not owe any candy in this case. Starting from house at index
Sample Input 2
5 2
Sample Output 2
6
Explanation 2
Starting at index
Comments