Find the sum of all nonnegative integers $n$ such that there are integers $a$ and $b$ with the property:

$n^2 = a+b \text{ and } n^3 = a^2 + b^2$

The answer is 3.

**
This section requires Javascript.
**

You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.

By try and error, we can get small answers which are $0,1,2$ . (When $n=2$ , $a=b=2$ .) Now, let us use quadratic equation to show that these are the only answers.

$\begin{aligned} n^3&=a^2+b^2 \\ &=(a+b)^2-2ab \\ ab&=\frac{n^4-n^3}{2} \\ a+b&=n^2 \end{aligned}$

We can get that $a, b$ are the roots of $x^2-n^2x+\frac{n^4-n^3}{2}=0$ . The discriminant of quadratic eqn above must bigger or equal to $0$ . Hence $\begin{aligned} n^4-2(n^4-n^3)\geq 0 \\ n^3(n-2) \leq 0 \\ 0\leq n \leq 2 \end{aligned}$ Hence, the required sum is $\large 0+1+2=3$ .