Observing Two Stars
InterviewTime limit1sMemory limit128 MB
Given start times and periods of two blinking stars, find the earliest simultaneous blink time and weekday, or report it never happens.
- Level
Medium5 of 10
- Topics
- Number theory, Math, Simulation
- Solved
- No attempts yet
Problem
Sanggeun and Junggeun are observing two stars for their astronomy class. For each star, they recorded the time it first blinked today and the period after which it blinks again. Each star keeps blinking forever at its own fixed period.
Today is Saturday, and the first time of a day is 00:00 midnight. Find the earliest time when the two stars blink at the same time.
Input
Four lines are given. Each line is a time in HH:MM format, where 0 <= HH <= 23 and 0 <= MM <= 59.
The first line is the time when the first star first blinked today, the second line is the time when the second star first blinked today, the third line is the blinking period of the first star, and the fourth line is the blinking period of the second star.
The first two times are always different. Today is Saturday. A blinking period is never 00:00.
Output
If the two stars never blink at the same time, print Never.
Otherwise, print the weekday of the earliest simultaneous blink on the first line. The weekday must be one of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday.
On the second line, print the time of that simultaneous blink in HH:MM format.