Sérgio chooses two positive integers $a$ and $b$. He writes 4 numbers in his notebook: $a, a+2, b$ and $b+2$. Then, all 6 products of two of these numbers are written on the board. Let $Q$ be the number of perfect squares written on it, determine the maximum value of $Q$.

#
Solution

Initially, we will prove that the product $a(a+2)$ is not a perfect square for any choice of $a$. We have two cases to consider:

i) If $a$ is odd, then no prime that divides $a$ can divide $a+2$. Therefore, $a$ and $a+2$ must each be a perfect square. This clearly has no solution for $a \geq 1$, as the difference between two perfect squares is at least 3.

ii) If $a$ is even, we have $a=2k$ for some positive integer $k$. Thus, $a(a+2)=2k(2k+2)=(2k+1)^2-1$. This is also not possible, as in this case we would have a perfect square between two consecutive perfect squares: $(2k)^2 < a(a+2) < (2k+1)^2$.

Therefore, the product $a(a+2)$ cannot be a perfect square. Moreover, $ab$ and $b(a+2)$ cannot both be perfect squares simultaneously, because in that case $ab \cdot b(a+2) = b^2 \cdot a(a+2)$ would be a perfect square, implying that $a(a+2)$ is also a perfect square, which contradicts the previous lemma. Similarly, $a(b+2)$ and $(a+2)(b+2)$ cannot both be perfect squares simultaneously. By symmetry, $(a+2)b$ and $(a+2)(b+2)$ cannot both be perfect squares at the same time.

Thus, the possible squares would be $ab, b(a+2), a(b+2)$, and $(a+2)(b+2)$. Excluding the products $a(a+2), b(b+2)$, and noting that in the pairs $(ab, b(a+2))$ and $(ab, a(b+2))$, only one of their members can be a perfect square, we can conclude that $Q \leq 3$. To have $Q=3$, $b(a+2), a(b+2), (a+2)(b+2)$ must all be squares. This is absurd, as we have already seen that $b(a+2)$ and $(a+2)(b+2)$ cannot be perfect squares simultaneously. Note that $Q=2$ can be achieved, for example, with $a=b=1$, since $ab=1^2$ and $(a+2)(b+2)=3^2$.