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.
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
Every connected component $V$ of $\operatorname{Spec}(A)$ is a closed set. Therefore $\operatorname{Spec}(A/I(V))$ is just that component. Therefore one can partition $\operatorname{Spec}(A)$ by the $\operatorname{Spec}(A/I(V))$. Every ring $B$ that has morphisms to each $A/I(V)$ has a universal morphism to $\prod A/I(V)$. Is this a quotient, when $B=A$? What's the kernel? In the other category, the morphism from $A$ induces a natural map from the spectrum of the product to $A$, whose topology certainly matches that of $A$.

I'M AWAKE, I'M AWAKE:

So, what I was hoping would make the statement elementary was that if $\operatorname{Spec}(A)$ had subspaces that matched the product's spectrum, the disjointness of the subspaces would imply the only topological difference there could be was whether all the subspaces of $\operatorname{Spec}(A)$ were closed like they are in the product spectrum. Since I wasn't doing the math, I forgot that if $A$ wasn't reduced it could have the same topology.

The surjectivity condition on the universal map reinforces the connection. That the kernel is the nilradical can checked several ways, but see Kidwell's answer for proving the nilradical is $\{0\}$.

W.l.o.g., let $f, g$ be quotient maps from $A$. Then the universal map $&lt;f,g&gt;:A\rightarrow A/\ker f \prod A/\ker g$ is surjective iff

$$\not \exists &lt;[y]_f,[z]_g&gt;: f^{-1}(y) \bigcap g^{-1}(z)=\emptyset$$
$$\iff \forall y, z \in A, \exists i \in \ker f, j \in ker g : y+i = z+j$$
$$\iff \forall y, z, y-z \in \ker f+ \ker g.$$

Thus surjectivity of the universal map holds iff the kernels are comaximal. Furthermore, comaximality implies disjoint varieties, and the radical of the sum of the kernels must be $A$ - which is just the sum of the kernels, if one is initially defining the kernels as $I(V)$ for $V$ a connected component.