Diophantine equation from "Solving mathematical problems" by Terence Tao 
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?
 A: He came up with the equation for $a$ by viewing the equation above as a quadratic in $a$.  The constant term is $b^2$ and the linear term is $b(2-n)$.  He plugged those into the quadratic formula to get the equation for $a$.  
Then we know that $a,b$ are integers, which means the square root must be an integer as well.  To have the square root be an integer, the thing you take the root of has to be the square of an integer, so $(n-2)^2-4$ must be a square.  The only squares that differ by $4$ are $0$ and $4$, so $(n-2)^2$ must be $0$ or $4$.  That would say $n$ could be $0,2,4$ but $0$ is clearly not allowed.
A: The author finds the identity
$$a= \frac{b}{2}[(n-2) \pm \sqrt{(n-2)^2-4}],$$
by applying the quadratic formula to the previous equation, which is a quadratic in $a$:
$$a^2+b(2-n)\cdot a+b^2=0.$$
Plugging the coefficients into the quadratic formula yields
\begin{eqnarray*}
a&=&\frac{-b(2-n)\pm\sqrt{(b(2-n))^2-4b^2}}{2}\\
&=&\frac{b(n-2)\pm\sqrt{(4b^2-4b^2n+b^2n^2)-4b^2}}{2}\\
&=&\frac{b(n-2)\pm\sqrt{b^2n^2-4b^2n}}{2}\\
&=&\frac{b(n-2)\pm|b|\sqrt{n^2-4n}}{2}\\
&=&\frac{b(n-2)\pm b\sqrt{(n-2)^2-4}}{2}\\
&=&\frac{b}{2}\Big((n-2)\pm\sqrt{(n-2)^2-4}\Big).
\end{eqnarray*}
Next, you can rewrite the equality
$$a= \frac{b}{2}[(n-2) \pm \sqrt{(n-2)^2-4}],$$
to isolate the square root. You will find that
$$\sqrt{(n-2)^2-4}=\pm\Big(2a-b(n-2)\Big).$$
Because $a$, $b$ and $n$ are integers, the right hand side is an integer. This means the term inside the square root is a perfect square; it means
$$(n-2)^2-4=\Big(2a-b(n-2)\Big)^2.$$

As a side note, the questions can be solved with far fewer computations by noting that
$$(a+b)^2=nab,$$
implies that $a$ divides $b$ and $b$ divides $a$, so $b=\pm a$. Because $a+b\neq0$ this means $a=b$ and the equation above becomes
$$na^2=(a+a)^2=4a^2,$$
which shows that $n=4$ because $a$ is nonzero.
A: 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.
A: $$a^2 +a\left[b(2-n)\right] + b^2 = 0$$
is a quadratic equation in $a$, so we apply the quadratic formula.  \begin{align*}
a &= \frac{-\left[b(2-n)\right] \pm \sqrt{\left[b(2-n)\right]^2 - 4(1)(b^2)}}{2}  \\
    &= \frac{-b(2-n)}{2} \pm \frac{1}{2}\sqrt{b^2( 4 - 4n + n^2) - 4b^2}  \\
    &= \frac{b}{2}(n-2) \pm \frac{1}{2}\sqrt{b^2( - 4n + n^2)}  \\
    &= \frac{b}{2}(n-2) \pm \frac{1}{2}|b|\sqrt{ n^2 - 4n + 4 - 4}  \\
    &= \frac{b}{2}(n-2) \pm \frac{1}{2}|b|\sqrt{ (n-2)^2 - 4}  \\
    &= \frac{b}{2} \left[ (n-2) \pm \sqrt{ (n-2)^2 - 4}  \right]  \text{,}
\end{align*}
where regardless of the sign of $b$, $\{|b|, -|b|\} = \{b,-b\} $ (in some order), so we get the last line.
We require $a$ is an integer, so the right hand side of this is an integer.  This requires $b[\dots]$ is an even integer (even, to cancel the division by $2$ at the front).  Now $n$ is a known integer, so $(n-2)^2 - 4$ is an integer.  Call this integer
$$  D = (n-2)^2 - 4  \text{.}  $$
If $D$ is a perfect square, $D = d^2$, then 
$$  \frac{b}{2} \left[ (n-2) \pm \sqrt{ D}  \right] = \frac{b}{2} \left[ (n-2) \pm d  \right]  \text{,}  $$
and, excepting the evenness requirement, everything in sight is sums differences and products of integers, so is an integer.
If $D$ is not a perfect square, $\sqrt{D}$ is not an integer; it isn't even a rational number.  So $(n-2) \pm \sqrt{ D}$ is an irrational number, and multiplying by the integer $b$ yields an irrational number.  Dividing by $2$ leaves the number irrational.  But $a$ is rational (it's even an integer), so this cannot be what happens.
