#P8831. Days Elapsed Since 1/1/1
Days Elapsed Since 1/1/1
Days Elapsed Since 1/1/1
Given a date, count the number of days that have elapsed from January 1, 1 AD to the given date according to the official calendar history. Before the year 1582 the Julian calendar is used – a leap year is any year that is a multiple of 4, and the months have fixed days: January (31), February (28, or 29 in a leap year), March (31), April (30), May (31), June (30), July (31), August (31), September (30), October (31), November (30) and December (31).
From October 15, 1582 onward the Gregorian calendar is observed. In the Gregorian calendar a leap year is determined by the rule: a year is a leap year if it is divisible by 4, except for years divisible by 100 but not divisible by 400. In addition, in order to correct the calendar error a shift was applied: October 4, 1582 was immediately followed by October 15, 1582 (i.e. the dates October 5 to October 14, 1582 do not exist).
Notes:
- If the given date is before October 15, 1582, assume the Julian calendar is used.
- If the given date is on or after October 15, 1582, the Gregorian calendar is used and the 10 missing days are not counted.
- The answer is defined as the number of days that have elapsed since January 1, 1 AD. Thus, if the input date is 1/1/1, the answer should be 0.
For any input date, guarantee that the date is valid (i.e. it will not fall in the non-existent range 1582-10-05 to 1582-10-14).
The final answer should be computed exactly according to the above rules.
Mathematical formulas (in LaTeX):
For the Julian calendar, a year \( y \) is a leap year if \[ y \bmod 4 = 0. \]
For the Gregorian calendar, a year \( y \) is a leap year if \[ \left(y \bmod 400 = 0\right) \quad \text{or} \quad \left((y \bmod 4 = 0) \land (y \bmod 100 \neq 0)\right). \]
inputFormat
The input consists of three positive integers: year
month
day
, separated by spaces.
outputFormat
Output a single integer – the number of days that have elapsed from January 1, 1 AD to the given date.
sample
1 1 1
0