Why is $Q!^{2P} \bmod{q} = ((q-1)!(-1)^Q)^P\bmod{q}$ I am studying a proof of the Quadratic Reciprocity Law by G.Rousseau ( which can be found here ). I have a question about the first page, line before last.
If $p,q$ are odd primes, $P=\frac{p-1}{2}$ and $Q=\frac{q-1}{2}$ then ( allegedly )
$$Q!^{2P} \bmod{q} = ((q-1)!(-1)^Q)^P\bmod{q},$$ probably Wilson's Theorem is applied.
I would like to a have a detailed working from Left Side to Right Side with an explanation of the theorem or rules applied.
 A: (The following is just a more detailed version of my comment above.)
We have $Q=\left(  q-1\right)  /2$ and thus $q-Q-1=Q$. Now,
$\left(  q-1\right)  !=\prod\limits_{k=1}^{q-1}k=\left(  \prod\limits_{k=1}^{Q}k\right)
\left(  \prod\limits_{k=Q+1}^{q-1}k\right)  $
$=\left(  \prod\limits_{k=1}^{Q}k\right)  \left(  \prod\limits_{k=1}^{q-Q-1}
\underbrace{\left(  q-k\right)  }_{\equiv-k\operatorname{mod}q}\right)  $
(here, we substituted $q-k$ for $k$ in the second product)
$\equiv\left(  \prod\limits_{k=1}^{Q}k\right)  \left(  \prod\limits_{k=1}^{q-Q-1}\left(
-k\right)  \right)  =\left(  \prod\limits_{k=1}^{Q}k\right)  \underbrace{\left(
\prod\limits_{k=1}^{Q}\left(  -k\right)  \right)  }_{=\left(  -1\right)  ^{Q}
\prod\limits_{k=1}^{Q}k}$
(since $q-Q-1=Q$)
$=\underbrace{\left(  \prod\limits_{k=1}^{Q}k\right)  }_{=Q!}\left(  -1\right)
^{Q}\underbrace{\prod\limits_{k=1}^{Q}k}_{=Q!}=Q!\left(  -1\right)  ^{Q}
Q!=Q!^{2}\left(  -1\right)  ^{Q}\operatorname{mod}q$.
Multiplying both sides of this congruence by $\left(  -1\right)  ^{Q}$, we obtain
$\left(  q-1\right)  !\left(  -1\right)  ^{Q}\equiv Q!^{2}\underbrace{\left(
-1\right)  ^{Q}\left(  -1\right)  ^{Q}}_{=\left(  -1\right)  ^{2Q}=1}
=Q!^{2}\operatorname{mod}q$.
Taking both sides of this congruence to the $P$-th power, we obtain
$\left(  \left(  q-1\right)  !\left(  -1\right)  ^{Q}\right)  ^{P}\equiv
Q!^{2P}\operatorname{mod}q$,
qed.
