Show that a ring with disconnected spectrum is a product of two subrings. It's an exercise from the book introduction to commutative algebra by Atiyah and Macdonald. If $\operatorname{Spec}(A)$ is disconnected, I'm asked to show that $A$ is a product of two subrings.
I know that $A/R$ is a product of two rings, where $R$ is the nilradical of $A$. What should I do? Also, my friend told me that it can be solved using the fact(I don't know it) that the category of affine schemes is isomorphic to the opposite category of rings, I don't understand how would this fact help. I want an elementary solution to this exercise. Thanks for any help.
 A: Suppose the spectrum $X=\mathrm{Spec}(A)$ is disconnected. This means that it is the disjoint union of two closed sets (which are also open). Closed sets of the spectrum are, by definition, the subsets of the form $V(I)$ for $I$ an ideal of $A$. So the assumption is that $X=V(I)\cup V(J)$ for some ideals $I,J$ with $V(I)\cap V(J)=\emptyset$. Now, in general, from the definition, one has $V(I)\cap V(J)=V(I+J)$, because a prime ideal of $A$ contains both $I$ and $J$ if and only if it contains $I$ and $J$, if and only if it contains $I+J$. So $V(I+J)=\emptyset$. This means that $I+J$ does not lie in any prime ideal of $A$, which means it cannot be a proper ideal: $I+J=A$. On the other hand, again from the definition, one has $V(I)\cup V(J)=V(IJ)$. Because $I+J=A$, one has $IJ=I\cap J$ (this is proved early on in A and M). In fact, for such ideals $I$ and $J$ (sometimes called comaximal ideals), A and M prove that the natural ring map $A\rightarrow(A/I)\times(A/J)$ is an isomorphism (this is an instance of the Chinese remainder theorem). So indeed $A$ decomposes as a product.
EDIT: As is pointed out by the OP in the comments, my argument is not complete. It only shows what the OP already apparently knew, that $A$ modulo its nilradical decomposes as a product. One needs to argue that idempotents lift modulo the nilradical. This is proved in both the answers to If $\mathop{\mathrm{Spec}}A$ is not connected then there is a nontrivial idempotent
