<s>[INST] 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. 
 [/INST] 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.
</s>