Biorhythms
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 130935 Accepted: 41750
Description
Some people believe that there are three cycles in a person's life that start theday he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best inthe corresponding field (physical, emotional or mental). For example, ifitisthe mental curve, thought processes will be sharper and concentration will be easier.
Since the three cycles have different periods, the peaks ofthe three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur inthe same day) for any person. For each cycle, you will be giventhenumberof days fromthebeginningofthe current yearat which one ofits peaks (not necessarily thefirst) occurs. You will also be given a date expressed asthenumberof days fromthebeginningofthe current year. You task isto determine thenumberof days fromthegivendatetothe next triple peak. The givendateisnot counted. For example, ifthegivendateis10andthe next triple peak occurs onday12, the answer is2, not3. If a triple peak occurs onthegivendate, you should give thenumberof days tothe next occurrence of a triple peak.
Input
You will be given a numberof cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are thenumberof days fromthebeginningofthe current yearat which the physical, emotional, and intellectual cycles peak, respectively. The value d isthegivendateand may be smaller than any of p, e, or i. All values are non-negative andat most 365, and you may assume that a triple peak will occur within 21252 days ofthegivendate. The endof input is indicated by a line in which p = e = i = d = -1.
Output
For each test case, print the case number followed by a message indicating thenumberof days tothe next triple peak, inthe form:
Case 1: the next triple peak occurs in1234 days.
Use the plural form ``days'' even ifthe answer is1.
Sample Input
00000001005203432545672831022332020330120340
-1 -1 -1 -1
Sample Output
Case 1: the next triple peak occurs in21252 days.
Case 2: the next triple peak occurs in21152 days.
Case 3: the next triple peak occurs in19575 days.
Case 4: the next triple peak occurs in16994 days.
Case 5: the next triple peak occurs in8910 days.
Case 6: the next triple peak occurs in10789 days.
Source
East Central North America 1999
BiorhythmsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 130935 Accepted: 41750DescriptionSome people believe that there are three cycles in a person's life that start the day