Algorithm to compute prime factors of n from whether x is a square?

46 Views Asked by At

Suppose there exists an algorithm that takes input $x \in \mathbb{Z}_{n}^{*}$ and returns the square root of $x$ if $x$ is a perfect square and nothing otherwise.

Use this algorithm to compute the prime factors of $n \in \mathbb{Z}$, with the added condition that $n = pq$, where $p$ and $q$ are distinct odd primes.

I believe this may have something to do with Fermat's factorization method, but I am stuck on how exactly to approach this.