Solution (source code)

= Solution

For an <idempotent> $e\in R$, define the <principal open subset> $D(e)\subseteq\operatorname{Spec}R$. Since $e(1-e)=0$, a <prime ideal> contains at least one of $e,1-e$, and it cannot contain both. Therefore
$$
D(e)=V(1-e),\qquad \operatorname{Spec}R=D(e)\sqcup D(1-e).
$$
Thus $D(e)$ is a <clopen set>.

Conversely, let $C$ be a <clopen set> in $T=\operatorname{Spec}R$. The <structure sheaf> glues the section $1$ on $C$ and the section $0$ on its complement to a unique <global section> $e\in\Gamma(T,\mathcal O_T)=R$. Checking on these two <open subsets> gives $e^2=e$, and $D(e)=C$. Conversely, the restriction of an <idempotent> $e$ to $D(e)$ is $1$ because $e$ is a <unit> there, and its restriction to $D(1-e)$ is $0$. Thus the two constructions are inverse, including for the zero <ring>:
$$
\boxed{\{e\in R:e^2=e\}\ \longleftrightarrow\ \{C\subseteq\operatorname{Spec}R:C\text{ clopen}\},\qquad e\longmapsto D(e).}
$$