Let $R$ be a commutative ring and $S$ a subring of $R$, i.e. a ring that may not contain the identity. Suppose that $S \subset A_1 \cup ... \cup A_n$ where $A_i$'s are ideals of $R$ and at least $n-2$ of which are prime ideals. Prove that $S$ is contained in one of the $A_i$'s.
I am totally lost on this one. I supposed on the contrary that there are $x, y \in S$ such that $x \in A_i$ but $y$ is not in $ A_i$, but am unsure how to go about from here. It seems that I might have to break it into two cases, one in which at least one of $x,y$ is in a prime ideal and the second in which neither $x$ or $y$ is in the prime ideal. Any help would be appreciated
This is known as the prime avoidance lemma. I will restate it as the contrapositive:
There is nothing to prove for $r=1$. For $r=2$, let $x, y \in J$ with $x \not\in I_1, y \not\in I_2$. If $x \not\in I_2$ or $y \not\in I_1$ we are done. Otherwise $x \in I_2, y \in I_1$, and then $x+y$ may not be in either of the ideals (why?).
For $r\geq 3$, by induction we may choose $x_i \in J \setminus \cup_{i \neq j} I_j$. If any of the $x_i$ are not in $I_i$ then we are done, so we suppose that $x_i \in I_i$. Without loss of generality let $I_r$ be prime, and consider $$ y = x_1 \dots x_{r-1} + x_r. $$ Then $y$ is in $J$ since it is an ideal. Now $y$ is not in $I_r$, or else $y - x_r = x_1 \dots x_{r-1} \in I_r$, so $x_i \in I_r$ for some $i < r$ by primeness. Also, $y$ is not in any of the $I_i$'s for $i < r$, or else $$ x_r = y - x_1 \dots x_{r-1} \in I_i, $$ another contradiction. So we win.