#P6484. Simultaneous Flashing Stars
Simultaneous Flashing Stars
Simultaneous Flashing Stars
There are two stars in the sky. Each star flashes periodically. For each star, you are given its first flash time and the interval (in minutes) between subsequent flashes. The day when the first flash occurs is a Saturday, and 00:00 marks the beginning of the day.
Your task is to compute the first moment (day and time) when both stars flash simultaneously. In other words, let the first flash time and period (in minutes) for the two stars be given as:
- Star 1: first flash at \( t_1 \) minutes and period \( p_1 \) minutes.
- Star 2: first flash at \( t_2 \) minutes and period \( p_2 \) minutes.
You are to find the smallest time \( T \) (in minutes since 00:00 of the starting Saturday) such that
[ T \equiv t_1 \pmod{p_1} \quad \text{and} \quad T \equiv t_2 \pmod{p_2}. ]
Then, convert \( T \) into a day and time. Note that one day has 1440 minutes. The day sequence starts from Saturday, followed by Sunday, Monday, Tuesday, Wednesday, Thursday, and Friday, then repeats.
Input Format: Two lines are given. The first line contains the first flash time of Star 1 in HH:MM format and its flashing interval (in minutes), separated by a space. The second line contains the first flash time of Star 2 in HH:MM format and its flashing interval (in minutes), separated by a space.
Output Format: Output the day of the week and the time (in HH:MM format) when both stars flash simultaneously, separated by a space.
inputFormat
The input consists of two lines:
HH:MM P HH:MM P
Where the first line represents Star 1's first flash time (HH:MM) and its flashing interval P (an integer in minutes), and the second line represents Star 2's first flash time and its flashing interval.
outputFormat
Output a single line containing the day of the week and time (in HH:MM format) separated by a space. For example, Saturday 00:15
.
sample
00:05 10
00:00 15
Saturday 00:15