In his algebraic geometry notes, Vakil suggests the exercise (remark 3.6.3) of showing that a ring $A$ is a product $A = A_1 \times A_2$ iff $\operatorname{Spec} A$ is disconnected.
His hint is to show that both conditions are equivalent to the existence of two elements $a_1, a_2 \in A$ s.t. $a_1^2 = a_1$, $a_2^2 = a_2$ and $(a_1 + a_2) = 1$, and hence $a_1a_2 = 1$.
2 questions: 1) Does it really follow that $a_1a_2 = 0$ from the other assumptions on $a_1$ and $a_2$ I tried deducing it but the most that I succeeded in showing was:
$$1=(a_1+a_2)^2 = a_1^2 + a_2^2 + 2a_1a_2 = a_1 + a_2 +2a_1a_2$$ $$0=2(a_1a_2)$$
However, I fail to see why this implies that $a_1a_2 = 0$, since he didn't mention any assumption of $2$ being regular.
2) How does one get that $\operatorname{Spec} A$ disconnected implies the existence of such $a_1,a_2$?
I reasoned the following:
taking $U = V(a_1), W = V(a_2)$ to be clopen sets such that $U\cap W = \varnothing$ and $U\cup W = \operatorname{Spec} A$ we get: $$\cup_{i\in I} D(f_i) = V(a_2)$$ $$\cup_{j\in J} D(f_j) = V(a_1)$$
where the left hand side is the expression of an open set as a union of basis elements and the right hand side is the definition of a closed set. From the fact that $V(a_1) \cup V(a_2) = V(a_1a_2) = \operatorname{Spec} A$ we get that $a_1a_2$ is nilpotent, but I can't seem to get anything else.