what is the formula for determining the next year in which a given month/day will occur on a specific weekday So, I was trying to express the formula for determining the next year on which a given date (month/day) will fall on a given weekday.  
The internet has plenty of sites that explain how to determine the weekday of an arbitrary date (at least up through the 39th century).  So I was able to get a good start.
The mod 7 of an offset number which can be calculated using specific formulas for day, month, year, and century will provide the "day number" of that date.  So, for desired day number of X where the Do = the Day offset for the day of the month and Mo = the month offset for the month of the year, and y = the year we want to find ( and where X, Do, and Mo are known) we can say that 
X-(Do +Mo)%7 = ((((39 - (floor(y/100)))%4)*2) % 7 + ((y%4) + (y%4)/4) % 7)%7
So in theory, all I have to do is solve for y, take the minimum and I have the next year that a month/day will fall on a particular weekday.  However I quickly realized that I don't have the first clue how to begin solving for y when there is a modulus operation in the expression.  
So I'd love help solving for y (and a check on my logic in constructing the above), or as a minimum, help with how to deal with modulus in solving/simplifying/reducing/operating on an algebraic expression.
 A: Here are some possibly helpful facts.
If March 1 falls on the same day of the week in the year $x$ and in the year $y$, then every other day from March 1 through December 1 falls on the same day of the week in the year $x$ and the year $y$, and every day from January 1 through February 28 falls on the same day of the week in the year $x + 1$ and in the year $y + 1$.  So to know how many years pass before a date falls on the same day of the week again, you just need to find the formula for March 1; you can apply it for any date, except that you have to subtract $1$ from the year number in that formula when the month is January or February.
Define the sequence $a_0, a_1, a_2, ...$ as follows:
$$
\begin{eqnarray}
a_0 =
a_1  & = &  6 \\
a_2  & = & 11 \\
a_3  & = &  5 \\
a_n  & = & a_{n-4} \ \ \mbox{for $4 \le n < 88$} \\
a_{88} =
a_{89}  & = &  6 \\
a_{90}  & = & 12 \\
a_{91}  & = &  5 \\
a_{92} =
a_{93} =
a_{94} =
a_{95}  & = &  6 \\
a_{96}  & = &  7 \\
a_{97}  & = & 12 \\
a_{98} =
a_{99}  & = &  6 \\
a_n  & = & a_{n-100} \ \ \mbox{for $100 \le n < 300$} \\
a_{300} =
a_{301}  & = &  6 \\
a_{302}  & = & 11 \\
a_{303}  & = &  5 \\
a_n  & = & a_{n-4} \ \ \mbox{for $304 \le n < 400$} \\
\end{eqnarray}
$$
Then March 1 in the year $2400 + k$ next falls on the same day of the week in the year $2400 + k + a_k.$
The number of years until February 29 falls on the same day of the week is longer, because there is not a February 29 every year. Define
$$
\begin{eqnarray}
b_0  & = &  28 \\
b_n  & = & b_{n-4} \ \ \mbox{for $4 \le n < 72$ such that $b_{n-4}$ is defined} \\
b_{72} =
b_{76} =
b_{80} =
b_{84} =
b_{88}  & = &  40 \\
b_{92} =
b_{96}  & = &  12 \\
b_n  & = & b_{n-100} \ \ \mbox{for $104 \le n < 300$ such that $b_{n-100}$ is defined} \\
b_{304}  & = &  28 \\
b_n  & = & b_{n-4} \ \ \mbox{for $308 \le n < 400$ such that $b_{n-4}$ is defined} \\
\end{eqnarray}
$$
Then February 29 in the year $2400 + k$ next falls on the same day of the week in the year $2400 + k + b_k.$
Other values of $b_n$ are undefined, because there is no February 29 in the corresponding year.
