Modular square root (source code)

= Modular square root
{title2=$x^2\equiv a\pmod m$}

A <modular square root> of a residue $a$ modulo $m$ is a residue $x$ with $x^2\equiv a\pmod m$. Such a root need not exist or be unique. Modulo seven, $2$ has the two roots $3,4$, while $3$ has none.

For an odd <prime> $p$, each nonzero <quadratic residue> has exactly two roots, $x$ and $-x$, because $X^2-a$ has at most two roots in a <field>. A composite modulus can have more: $1$ has four roots modulo eight. For coprime factors of $m$, the <Chinese remainder theorem> combines local roots into all roots modulo $m$.