Solution (source code)

= Solution

For an odd <prime number> $p$, <Euler's criterion> states that
$$
\boxed{a^{(p-1)/2}\equiv\left(\frac ap\right)\pmod p,}
$$
where the <Legendre symbol> is zero if $p\mid a$, one if $a$ is a nonzero <quadratic residue>, and minus one otherwise. Including the zero case makes this formulation valid for every <integer> $a$.

Apply <Euler's criterion> to $a$, $b$, and $ab$. Multiplication in <modular arithmetic> gives
$$
\left(\frac{ab}p\right)\equiv (ab)^{(p-1)/2}
\equiv a^{(p-1)/2}b^{(p-1)/2}
\equiv\left(\frac ap\right)\left(\frac bp\right)\pmod p.
$$
If $p$ divides either factor, both sides are zero. Otherwise both sides belong to $\{-1,1\}$; these two values are distinct modulo the odd <prime number> $p$. The congruence is therefore an equality of <integers>, proving <multiplicativity of the Legendre symbol>:
$$
\boxed{\left(\frac{ab}p\right)=\left(\frac ap\right)\left(\frac bp\right).}
$$