Equality of products of reduced residue classes I am working on the following problem:

Suppose $n>1$. Prove that
$$
\prod_{\substack{1\leq a\leq n\\(a,n)=1}}a\equiv\prod_{\substack{1\leq b\leq n\\(b,n)=1\\b^2\equiv1\pmod n}}b\pmod n.
$$

A computer program seems to show that for each $n$, the product either equals $1\pmod n$ or $n-1\pmod n$. Why is this the case, and how may I prove the result?
Looking at the product on the right, if $(b,n)=1$ and $b^2\equiv1\pmod n$ then I am inclined to think $b=1$, however clearly this is not the case. What is faulty with my reasoning? Any help would be appreciated!
 A: First of all, name the multiplicative inverse of any $t$ (mod $n$ clearly) as $t^*$. Now trivially the elements of the reduced residue class fall into two disjoint sets :
$i)$ Set $A$ consisting of all elements whose multiplicative inverse is equal to themselves.
$ii)$ Set $B$ consisting of all elements whose multiplicative inverse is not equal to themselves.
Now one can say that $$\displaystyle\prod_{1\leqslant a\leqslant n\\(a,n)=1}a=\displaystyle\prod_{1\leqslant a\leqslant n\\(a,n)=1\\{a\in A}}a\displaystyle\prod_{1\leq a\leq n\\(a,n)=1\\a\in B}a$$
Now note that $A$ is made of a pair of residues that in each pair the two numbers are multiplicative inverses of each other mod $n$ so $\displaystyle\prod_{1\leqslant a\leqslant n\\(a,n)\\a\in A}\overset{n}{\equiv}1$
Hence:$$\displaystyle\prod_{1\leqslant a\leqslant n\\(a,n)=1}a=\displaystyle\prod_{1\leqslant a\leqslant n\\(a,n)=1\\{a\in A}}a\displaystyle\prod_{1\leq a\leq n\\(a,n)=1\\a\in B}a=\displaystyle\prod_{1\leqslant a\leqslant n\\(a,n)\\a\in B}$$
But $B$ is the set of all residues whose multiplicative inverse is equal to themselves so for each element $b\in B$, we have $b^2\overset{n}{\equiv}1$ and hence: $$\prod_{\substack{1\leq a\leq n\\(a,n)=1}}a\equiv\prod_{\substack{1\leq b\leq n\\(b,n)=1\\b^2\overset{n}{\equiv}1}}b$$
