Discriminant criterion for a quadratic congruence modulo an odd prime (source code)

= Discriminant criterion for a quadratic congruence modulo an odd prime

Let $p$ be an <odd prime> and let $a,b,c$ be <integers> with $p\nmid a$. The <quadratic congruence>
$$
aX^2+bX+c\equiv0\pmod p
$$
has a solution exactly when its <discriminant> $\Delta=b^2-4ac$ is zero or a <quadratic residue> modulo $p$.

Indeed, <completing the square> gives the equivalent equation
$$
(2aX+b)^2\equiv\Delta\pmod p.
$$
Multiplication by $2a$ and translation by $b$ give a <bijection> of the <residue classes>, because $2a$ is invertible modulo $p$. Each square root $r$ of $\Delta$ therefore gives exactly one solution $X\equiv(r-b)(2a)^{-1}\pmod p$.

Consequently the number of distinct solutions is $1+(\Delta/p)$, using the <Legendre symbol>: one for zero <discriminant>, two for a nonzero <quadratic residue>, and none for a <quadratic nonresidue>. The hypotheses matter: if $p\mid a$ the equation can become linear, while at $p=2$ division by $2a$ is unavailable.