We suppose that $n$ is equal with the product of two distinct primes, let the primes $p$ and $q$, which we do not know. We are given a non-trivial square root of $1$ modulo $n$, i.e. a number $x \in \mathbb{Z}$ such that $x^2 \equiv 1 \pmod{n}$, but $x \not\equiv \pm 1 \pmod{n}$. I want to describe how we can find easily the prime factorization of $n$, i.e. $p$ and $q$.
I have thought the following.
We have that $x^2 \equiv 1 \pmod{n}$ and so
$$(x-1)(x+1) \equiv 0 \pmod{n}. $$
So $n \mid (x-1)(x+1)$ and so
$p \mid (x-1)(x+1)$ and $q \mid (x-1)(x+1)$.
Thus $p \mid x-1$ or $p \mid x+1$ and $q \mid x-1$ or $q \mid x+1$.
But can we find like that the primes $p$ and $q$ ? If so, how? Or do we have to do something else?
Since $x\not\equiv \pm 1\bmod n$, it follows that $p$ and $q$ will not both divide $x-1$, and they will not both divide $x+1$.
Therefore $$\{p,q\}=\{\gcd(x-1,n),\gcd(x+1,n)\}$$