Editorial for COCI '09 Contest 3 #6 Planete


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

With XY we denote that X divides Y, i.e. there exists k such that kX=Y.

Let us denote with X1,X2,,Xm duration of events in days. Note that saying:

  • "Between dates A and B there were α1 events 1, α2 events 2, etc."

is the same as saying:

  • "365(α1X1+α2X2++αmXm(BA))".

where BA is the difference in days between dates A and B. Further, we can split that into:

  • "5(α1X1+α2X2++αmXm+AB)"
  • "73(α1X1+α2X2++αmXm+AB)"

(note that 365=5×73). Since 5 and 73 are prime numbers, using Gaussian elimination, we can find all possible remainders of X's when divided by 5 and 73 (separately). Using the Chinese remainder theorem, we can further determine the remainder of each X when divided by 365.


Comments

There are no comments at the moment.