#Q219. 「一本通 6.4 练习 3」Biorhythms
「一本通 6.4 练习 3」Biorhythms
Description
Original source: POJ 1006
Humans are born with three biological cycles: physical, emotional, and intellectual, with cycle lengths of days, days, and days, respectively. Each cycle has one peak day. On the peak day, a person excels in the corresponding aspect. For example, during the peak of the intellectual cycle, one might think more sharply and concentrate more easily. Because the cycle lengths differ, the peaks of the three cycles usually do not occur on the same day. For each individual, we want to know when all three peaks coincide. For each cycle, we are given the number of days from the first day of the current year to the peak day (not necessarily the first occurrence of the peak).
Your task is, given a starting day (counted from the first day of the year), to output the next time all three peaks coincide (the number of days after the given time, not including the given time itself).
For example: if the given time is , and the next occurrence of all three peaks on the same day is , then output (note that it is not ).
Input Format
There are multiple test cases.
For each test case, input four integers , and . Here, represent the days from the first day of the year to the peak days of the physical, emotional, and intellectual cycles, respectively. is the given starting day, which may be smaller than , or .
The input ends when .
Output Format
From the given starting day, output the next occurrence when all three peaks coincide (the number of days after the given time). Use the following format:
Case 1: the next triple peak occurs in 1234 days.
Note: Even if the result is day, use the plural form days.
Sample 1
0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1
Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.
Constraints & Hint
All given times are non-negative and less than , and the sought time is less than .