Editorial for COCI '10 Contest 4 #3 Astro
Submitting an official solution before solving the problem yourself is a bannable offence.
First, convert all timestamps to minutes. Now, find the minute at which both stars flash. How? Let  and 
 be minutes at which the stars flashed and let 
 and 
 be the periods (in minutes) between consecutive flashes, accordingly. The first star thus flashes at the following minutes: 
. More generally: it flashes at minutes 
 for non-negative integers 
.
Assume that flash overlapping, if it occurs, will occur for  less than 
 (it can be proved that taking 
 less than 
 suffices, which is left as an exercise for the reader). For each such 
, we determine whether the second star will flash at the minute 
. Note that this will happen whenever the equation 
 holds. Therefore, it is sufficient to check whether 
 is a non-negative integer - in that case, the flash occurs, indeed.
Once the first overlapping is found, the corresponding minute needs to be converted to days and hours and outputted. In case none was found for any , we output 
Never.
Comments