## Discrete Mathematics with Applications 4th Edition

a. i. Saturday (6) ii. Friday (5) b. The final result is modulo 7 simply because we want there to be 7 possible outputs, one for each day of the week. We look at the first term, $n$, last. The second term, $floor(\frac{n-1}{4})$, is added in because it tells the mod function to boost the day of the week by 1 after every year divisible by 4. Since the extra day occurs at the end of February each leap year, January 1 of leap year is not affected, but January 1 of the following year is affected. This is why we take the floor of $\frac{n-1}{4}$ rather than $\frac{n}{4}$. The third term sets January 1 back every 100 years to cancel out the effect of the day added by the previous term. We use $n-1$ instead of $n$ for the same reason as before. Hence, for example, the year $1896$ was a leap year, and so was $1904$, but $1900$ was not: the world went eight years without a leap year instead of the usual four. The fourth term undoes the effect of the third term ("restoring" the effect of the first term) every four centuries. Hence, the year $2000$ was a leap year, and so January 1 of 2001 was a day later than if the previous year had not been divisible by 400. Finally, the first term, $n$, is simply there for convenience. It just so happens that $365\ mod\ 7=1$; that is, if year $n$ is not a leap year, then January 1 of year $n+1$ will occur one day of the week after January 1 of year $n$. Hence, we need some term of the form $n+b$, for some integer $b$, in our mod function, to induce this property. It also just so happens that $b=0$ does the trick, or for that matter, any $b$ divisible by 7. This is a simple result of the fact that, when the Gregorian Calendar was adopted by the Papacy in October 1582, it was set up so that January 1, 1583 (the first New Year's Day under this calendar) was a Saturday. Had they chosen that day to be, say, a Tuesday, we might make our first term $n-4$ or $n+3$ instead.