Consider the following problem: The square of the difference of two numbers is the same as their sum. What numbers satisfy this condition?

We might begin by expressing the problem as an equation: $$(a - b)^2 = a + b$$. Then we can look for possible solutions. Let's try to simplify the expression:

$$\begin {eqnarray} a^2 - 2ab + b^2 &=& a + b \\ a^2 - 2ab + b^2 - a - b &=& 0 \\ a^2 - (2b + 1)a + (b^2 - b) &=& 0 \end {eqnarray}$$

Solving for $$a$$ yields:

$$\begin {eqnarray} a &=& {{(2b + 1) \pm \sqrt{(2b + 1)^2 - 4(b^2 - b)}} \over 2} \\ a &=& {{(2b + 1) \pm \sqrt{(4b^2 + 4b + 1) - 4b^2 + 4b}} \over 2} \\ a &=& {{(2b + 1) \pm \sqrt{8b + 1}} \over 2} \end {eqnarray}$$

This last equation has an integer solution whenever $$8b + 1$$ is a perfect square. This is so because as long as $$b$$ is an integer, both $$(2b + 1)$$ and $$(8b + 1)$$ will be odd. Their sum or difference will be even, so $$a$$ will be a whole number. So all we need to do is find values for $$b$$ that make $$8b + 1$$ a perfect square. For example, if $$b = 1$$, then $$8b + 1 = 9$$ is a perfect square; or if $$b = 3$$, then $$8b + 1 = 25$$ is a perfect square. But if $$b = 5$$, then $$8b + 1 = 41$$ is not a perfect square. This is still a hit or miss way of solving the problem. We have two solutions:

$$\begin {eqnarray} b = 1 \rightarrow a &=& {{(2 \times 1 + 1) \pm \sqrt{8 \times 1 + 1}} \over 2} \\ a &=& {{3 \pm 3} \over 2} \\ a &=& 0, 3 \end {eqnarray}$$

This leads to the pair of solutions: $$(0 - 1)^2 = (0 + 1)$$ and $$(3 - 1)^2 = (3 + 1)$$. We also have:

$$\begin {eqnarray} b = 3 \rightarrow a &=& {{(2 \times 3 + 1) \pm \sqrt{8 \times 3 + 1}} \over 2} \\ a &=& {{7 \pm 5} \over 2} \\ a &=& 1, 6 \end {eqnarray}$$

This leads to the pair of solutions: $$(1 - 3)^2 = (1 + 3)$$ and $$(6 - 3)^2 = (6 + 3)$$.

We would like to develop a more general solution, though: one that does not involve trial and error. Let's try a slightly different approach to the question of finding perfect squares that can be expressed as $$8b + 1$$. If we divide $$8b + 1$$ by 8 for any whole number $$b$$, the remainder will always be 1.

### Generalizing the Solution

So let's ask this question: What perfect squares give a remainder of 1 when divided by 8? We can start with a list of perfect squares and their remainders:

Square

Remainder

1

1

4

4

9

1

16

0

25

1

36

4

49

1

64

0

81

1

It certainly looks as though every odd square gives a remainder of 1 when divided by 8. Consider the odd square $$(2n - 1)^2$$: $$\begin {eqnarray} (2n - 1)^2 &=& 4n^2 - 4n + 1 \\ &=& 4n(n - 1) + 1 \end {eqnarray}$$

Clearly if $$n$$ is even, then $$4n(n - 1)$$ is divisible by $$8$$. Likewise, if $$n$$ is odd, then $$(n - 1)$$ is even, and again $$4n(n - 1)$$ is divisible by 8. Therefore, whether $$n$$ is even or odd, $$(2n - 1)^2$$ has a remainder of 1 when divided by 8. We now have a method for generating solutions. For every odd square, subtract $$1$$ and divide by $$8$$ to get $$b$$ Then use the value of $$b$$ to obtain the value of $$a$$ Using the equation above, we can express $$b$$ as $${{[4n(n - 1) + 1] - 1} \over 8}$$. This simplifies to $$b = {{n(n - 1)} \over 2}$$. This works for any whole number $$n$$. We can substitute this value to solve for $$a$$.

$$\begin {eqnarray} a &=& {{2\left({n(n - 1) \over 2}\right)} + 1 \pm \sqrt{8\left({n(n - 1) \over 2}\right) + 1} \over 2} \\ &=& {{n^2 - n + 1 \pm (2n - 1)} \over 2} \\ &=& {{n^2 + n} \over 2}, {{n^2 - 3n - 2} \over 2} \\ a &=& {n(n + 1) \over 2}, {(n - 1)(n - 2) \over 2} \end {eqnarray}$$

For every number $$n$$, there exist two other numbers $$a = {n(n + 1) \over 2}$$ and $$b = {n(n - 1) \over 2}$$ such that $$(a - b)^2 = a + b$$. If these numbers look familiar, it is because they are triangle numbers. A triangle number has the form $$T_{n} = {n(n + 1) \over 2}$$. It should be apparent that $$T_{n - 1} = {n(n - 1) \over 2}$$ and $$T_{n - 2} = {(n - 1)(n - 2) \over 2}$$. For any two adjacent triangle numbers $$T_{n - 1}$$ and $$T_{n}$$ their difference $$T_{n} - T_{n - 1} = n$$ and their sum $$T_{n} + T_{n - 1} = n^2$$. So any two adjacent triangle numbers will satisfy the original conditions of the problem. For example, $$(21 - 15)^2 = 21 + 15$$.