If $x^2\equiv 1 \pmod{n}$ and $x \not\equiv \pm 1 \pmod{n}$, then either $\gcd(x-1,n)$ or $\gcd(x+1,n)$ is a nontrivial factor of n I'm reading elementary number theory and trying to understand the following problem: If $x^2\equiv 1 \pmod{n}$, $n=pq$, $p$ and $q$ are odd primes and $x \not\equiv \pm 1 \pmod{n}$, then either $\gcd(x-1,n)$ or $\gcd(x+1,n)$ is a nontrivial factor of $n$.
EDIT: Andreas Caranti wrote an updated, corrected version of my problem, so I wrote the definition again. 
 A: I assume your primes are odd and distinct. Also, your statement is not correct as written, you have to add $x \not\equiv \pm 1 \pmod{n}$. The latter assumption implies that $\gcd(x-1, n), \gcd(x+1, n) < n$.
You have $n \mid x^{2} - 1 = (x-1)(x+1)$. Now if $\gcd(x - 1, n) = 1$, then $n$ divides $x + 1$, a contradiction, as we have taken $x \not\equiv -1 \pmod{n}$. So $\gcd(x - 1, n) > 1$. Similarly, $\gcd(x + 1, n) > 1$. 
It follows that $\gcd(x-1,n)$ and $\gcd(x+1, n)$ are nontrivial, proper divisors of $n$, hence $p$ or $q$.
A: If not, by Euclid's Lemma, $\ (n,x\pm1)=1\,\Rightarrow\, (n,(x\!-\!1)(x\!+\!1)) = 1,\,$ contra $\, n\mid x^2-1$.
Or, more directly,  $\ (x\!-\!1)(x\!+\!1) = pqk,\, $ so, by unique factorization, the prime $\,p\,$ is a factor of one of $\, x\!-\!1,\ x\!+\!1,\,$ so $\,q\,$ is a factor of the other one (else both primes divide the same factor, so $\, n = pq\,$ divides $\,x\!-\!1\ \ {\rm or}\ \ x\!+\!1,\,$ contra hypothesis).
A: If $n=p\cdot q$ divides $x^2-1=(x+1)(x-1)$
If odd prime $r$ divides $x-1$ and $x+1,$ it will divide $(x+1)-(x-1)=2$ which is impossible $\implies r$ can divide exactly one of  $x-1,x+1$
Now let us check the possibilities 
Case $1:$   $p$ divides $x-1$ and $q$ divides $x-1\implies (x-1)$ is divisible by lcm$(p,q)=pq=n\implies x\equiv1\pmod n$ which is not acceptable according to the given condition.
Similarly, Case $2:$ $p$ divides $x+1$ and $q$ divides $x+1$ is discarded
Case $3:$  $p$ divides $x-1$ and $q$ divides $x+1$
Then $x-1=p\cdot a,x+1=q\cdot b$ where $a,b$ are some integers
i.e., $q\cdot b-p\cdot a=2$ , we can always find such $a,b$ using Bézout's Lemma as $(p,q)=1$
If $q$ divides $a,$ the LHS will be divisible by $q$
$\implies 2$ must be divisible by $q$ which is impossible $\implies (q,a)=1$
Now, gcd$(x-1,n)=$gcd$(p\cdot a,p\cdot q)=p\cdot$gcd $(a,q)=q$ as gcd$(a,q)=1$ 
Case $4$  $p$ divides $x+1$ and $q$ divides $x-1$ can be handled similarly.
