Solution (source code)

= Solution

For odd coprime positive <integers> $a=\prod_i p_i^{e_i}$ and $b=\prod_j q_j^{f_j}$, define the <Jacobi symbol> by multiplying <Legendre symbols> over the prime factorization of the denominator. Multiplicativity in the numerator gives
$$
\left(\frac ab\right)\left(\frac ba\right)=\prod_{i,j}\left[\left(\frac{p_i}{q_j}\right)\left(\frac{q_j}{p_i}\right)\right]^{e_if_j}.
$$
By <quadratic reciprocity> for the <Legendre symbol>, this is $(-1)^{UV}$, where $U=\sum_i e_i(p_i-1)/2$ and $V=\sum_j f_j(q_j-1)/2$. For odd $x,y$, $(xy-1)/2\equiv(x-1)/2+(y-1)/2\pmod2$, since $(x-1)(y-1)/2$ is even. Thus $U\equiv(a-1)/2$ and $V\equiv(b-1)/2\pmod2$. We obtain
$$
\boxed{\left(\frac ab\right)\left(\frac ba\right)=(-1)^{(a-1)(b-1)/4}.}
$$
If $a,b$ are not coprime, both symbols are zero and the equivalent identity $(a/b)=(-1)^{(a-1)(b-1)/4}(b/a)$ still holds. The convention $(a/1)=1$ handles denominator one.