Find all integers $n$ such that the equation $\frac{1}{a} + \frac{1}{b} = \frac{n}{a+b}$ is satisfied for some non-zero values of $a$ and $b$ (with $a + b \neq 0$).
I'm reading "Solving mathematical problems" by Terence Tao and I'm a bit stuck on this particular example. It starts as follows:
First multiplying out the denominators we get
$$\frac{a+b}{ab} = \frac{n}{a+b}$$
and from here follows $$(a+b)^2 = nab.$$
Now expanding this we get
$$a^2+2ab+b^2-nab=0 \Leftrightarrow a²+ab(2-n)+b^2.$$
From here on he suggests to use the quadratic formula to get
$$a= \frac{b}{2}[(n-2) \pm \sqrt{(n-2)^2-4}]$$
which I don't quite see how he came up with...
Also he then notes that "This looks very messy, but actually we can turn this messiness to our advantage. We know that $a, b$, and $n$ are integers, but there is a square root in the formula. Now this can only work if the term inside the square root, $(n-2)^2-4$ is a perfect square."
Could someone enlighten me on the part "Now this can only work if the term inside the square root, $(n-2)^2-4$ is a perfect square." what is he stating right here?
Regarding your first equation, with the formula
$$a^2+ab(2-n)+b^2 \tag{1}\label{eq1A}$$
consider that $n$ and $b$ are constants, with only $a$ being a variable. In that case, it's a quadratic polynomial in $a$, of the form
$$a^2 + ca + d \tag{2}\label{eq2A}$$
where $c = b(2-n)$ and $d = b^2$. Thus, using the quadratic formula gives
$$\begin{equation}\begin{aligned} a & = \frac{-c \pm \sqrt{c^2 - 4d}}{2} \\ & = \frac{-b(2-n) \pm \sqrt{(-b(2-n))^2 - 4(b^2)}}{2} \\ & = \frac{b}{2}\left((n - 2) \pm \sqrt{(n-2)^2 - 4}\right) \end{aligned}\end{equation}\tag{3}\label{eq3A}$$
Next, note that since $n$ is an integer, if $(n-2)^2 - 4$ is not a perfect square, then $\sqrt{(n-2)^2 - 4}$ would be irrational, so that $a$ determined from \eqref{eq3A} would also be irrational and, thus, not an integer as required. This is why it's required for $(n-2)^2 - 4$ to be a perfect square.