problem of number theory N. Sato Can someone help me solve this problem?

Sato, 4.2.
For an odd positive integer $n>1$, let $S$ be the set of integers $x$ such that $1 \leq x \leq n$, such that both $x$ and $x+1$ are relatively prime to $n$. Show that $$\prod_{x\in S}x \equiv 1 \mod n$$

Thanks Giorgio Viale
 A: If $n$ is even, $S$ is empty and $\prod_{x\in S} x = 1$.
Suppose $n$ is odd. We have to prove that $\prod_{x\in S} x \equiv 1 \mod p^k$, for every prime $p$ and $k \in \mathbb{N}$ such that $p^k|n$.
Let $p_1^{e_1}p_2^{e_2}...p_m^{e_m}$ be the prime factorisation of $n$. By the Chinese Remainder Theorem there are exactly $a = p_1^{e_1-1}(p_1-2)p_2^{e_2-1}(p_2-2)...p_m^{e_m-1}(p_m-2)/p_l^{e_l-1}(p_l-2)$ numbers $1 \leq x \leq n$ which are congruent to $1,...,p_k-3$ or $p_k-2$ modulo $p_k^{e_k}$ for all $1 \leq k < l$ and $l < k \leq n$ and congruent to some specific integer modulo $p_l^{e_l}$. This $a$ is an odd number, since all prime factors of $n$ are odd.
Therefore $$\prod_{x\in S} x \equiv \left(\prod_{x\in\{1,...,p_l^{e_l}\}\cap\{y:p_l\nmid y(y+1)} x \right)^a \equiv \left(\left(\prod_{x\in\{1,...,p_l^{e_l}\}\cap\{y:p_l\nmid y\}} x\right) \left(\prod_{x\in\{1,...,p_l^{e_l}\}\cap\{y:p_l\mid y-1\}} x \right)^{-1}\right)^a\equiv \left(-1\cdot((p_l-1)(2p_l-1)...(p_l^{e_l}-1))^{-1}\right)^{a}$$
The inverses of $p_l-1,2p_l-1,...,p_l^{e_l}-1$ modulo $p_l^{e_l}$ are $p_l-1,2p_l-1,...,p_l^{e_l}-1$ in some order, because there product should be $1 \mod p_l$. 
So $\left((p_l-1)(2p_l-1)...(p_l^{e_l}-1)\right)^2 \equiv 1 \mod p_l^{e_l}$. 
So $p_l^{e_l} | \left((p_l-1)(2p_l-1)...(p_l^{e_l}-1)-1\right)\left((p_l-1)(2p_l-1)...(p_l^{e_l}-1)+1\right)$. The two factors differ 2, so they can't be both divisable by $p_l$. Therefore $(p_l-1)(2p_l-1)...(p_l^{e_l}-1) \equiv 1 \mod p_l^{e_l}$ or $(p_l-1)(2p_l-1)...(p_l^{e_l}-1) \equiv -1 \mod p_l^{e_l}$. $(p_l-1)(2p_l-1)...(p_l^{e_l}-1) \equiv -1 \mod p_l$ and therefore $(p_l-1)(2p_l-1)...(p_l^{e_l}-1) \equiv -1 \mod p_l^{e_l}$.
So 
$$\prod_{x\in S} x \equiv \left(-1\cdot((p_l-1)(2p_l-1)...(p_l^{e_l}-1))^{-1}\right)^{a} \equiv 1^a \equiv 1 \mod p_l^{e_l}$$
A: Wilson's theorem says if $n$ is prime, $(n-1)! ≡ -1$ (mod $n$). Then $n-1$ isn't included, because $n$ is divisible by $n$. The product of the rest of the factors gives 1.
If $n$ isn't a prime, let its powered prime factors be $p_1$, $p_2$, ..., $p_y$, and respective remainders an $x$ candidate gives by being divided by them be $r_1$, $r_2$, ..., $r_y$ . No $r_a$ can equal 0 or one less than a multiple of the prime base of $p_a$ ($b_a$), so the possible remainders progress like 1, ... $b_a-2$, $b_a+1, ..., 2b_a-2, ...$ for each $p_a$. The number of the $x$ candidates allowing $r_a$ to be a given value is the same for any possible $r_a$ value, because all the given remainder combinations are possible. Therefore, the product is equivalent to 1 mod $p_a$, which can be said for every factor.
