Watching Watches
Time limit1sMemory limit128 MB
Two slow 12-hour analog watches are set to midnight; find the next time they read the same, rounded to the nearest minute.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Simulation, Implementation
- Solved
- No attempts yet
Problem
It is often said that a watch that has stopped keeps better time than one that loses 1 second per day: the stopped watch shows the correct time twice a day, while the watch that loses 1 second per day is correct only once every 43,200 days. This applies to old-fashioned 12-hour analog watches, whose hands move continuously (most digital watches would show nothing at all if stopped).
Consider two such analog watches. Both are set correctly at midnight and then run at a constant rate, but they run slow, losing and seconds per day respectively. What time will the watches show the next time they display exactly the same time? At that moment both watches read the same time, so there is a single answer.
Input
The input consists of several lines. Each line contains two distinct non-negative integers and with , giving the number of seconds per day that each watch loses. Read lines until end of input.
Output
For each line of input, print , , and the time displayed when the two watches next agree, rounded to the nearest minute, in the format k m HH:MM. The time is read on a 12-hour dial, so the hour is one of 12, 01, 02, ..., 11, and both the hour and the minute are written with two digits.