eolymp
bolt
Try our new interface for solving problems
Problems

Clock Hands

Clock Hands

We have an analog clock whose three hands (the second hand, the minute hand and the hour hand) rotate quite smoothly. You can measure two angles between the second hand and two other hands. Write a program to find the time at which "No two hands overlap each other" and "Two angles between the second hand and two other hands are equal" for the first time on or after a given time. \includegraphics{https://static.e-olymp.com/content/69/6937b06843081dea07653fb1c7893379b729906e.jpg} \textit{\textbf{Figure 1}}. Angles between the second hand and two other hands Clocks are not limited to \textbf{12}-hour clocks. The hour hand of an \textbf{H}-hour clock goes around once in \textbf{H} hours. The minute hand still goes around once every hour, and the second hand goes around once every minute. At \textbf{0:0:0} (midnight), all the hands are at the upright position. \InputFile The input consists of multiple datasets. Each of the dataset has four integers \textbf{H}, \textbf{h}, \textbf{m} and \textbf{s} in one line, separated by a space. \textbf{H} means that the clock is an \textbf{H}-hour clock. \textbf{h}, \textbf{m} and \textbf{s} mean hour, minute and second of the specified time, respectively. You may assume \textbf{2} ≤ \textbf{H} ≤ \textbf{100}, \textbf{0} ≤ \textbf{h} < \textbf{H}, \textbf{0} ≤ \textbf{m} < \textbf{60}, and \textbf{0} ≤ \textbf{s} < \textbf{60}. The end of the input is indicated by a line containing four zeros. \includegraphics{https://static.e-olymp.com/content/89/8935ee37475deea03777346303e153669c58c9d9.jpg} \textit{\textbf{Figure 2}}. Examples of \textbf{H}-hour clock (\textbf{6}-hour clock and \textbf{15}-hour clock) \OutputFile Output the time \textbf{T} at which "No two hands overlap each other" and "Two angles between the second hand and two other hands are equal" for the first time on and after the specified time. For \textbf{T} being \textbf{h_o:m_o:s_o} (\textbf{s_o} seconds past \textbf{m_o} minutes past \textbf{h_o} o’clock), output four non-negative integers \textbf{h_o}, \textbf{m_o}, \textbf{n}, and \textbf{d} in one line, separated by a space, where \textbf{n/d} is the irreducible fraction representing \textbf{s_o}. For integer \textbf{s_o} including \textbf{0}, let \textbf{d} be \textbf{1}. The time should be expressed in the remainder of \textbf{H} hours. In other words, one second after \textbf{(H−1):59:59} is \textbf{0:0:0}, not \textbf{H:0:0}.
Time limit 10 seconds
Memory limit 256 MiB
Input example #1
12 0 0 0
12 11 59 59
12 1 56 0
12 1 56 3
12 1 56 34
12 3 9 43
12 3 10 14
12 7 17 58
12 7 18 28
12 7 23 0
12 7 23 31
2 0 38 29
2 0 39 0
2 0 39 30
2 1 6 20
2 1 20 1
2 1 20 31
3 2 15 0
3 2 59 30
4 0 28 48
5 1 5 40
5 1 6 10
5 1 7 41
11 0 55 0
0 0 0 0
Output example #1
0 0 43200 1427
0 0 43200 1427
1 56 4080 1427
1 56 47280 1427
1 57 4860 1427
3 10 18600 1427
3 10 61800 1427
7 18 39240 1427
7 18 82440 1427
7 23 43140 1427
7 24 720 1427
0 38 4680 79
0 39 2340 79
0 40 0 1
1 6 3960 79
1 20 2400 79
1 21 60 79
2 15 0 1
0 0 2700 89
0 28 48 1
1 6 320 33
1 6 40 1
1 8 120 11
0 55 0 1
Source ACM International Collegiate Programming Contest, Asia Regional Contest, Aizu, 2013–11–24