-1

Find the sum of all positive integers $n$ for which $n^2-7n+21$ is a perfect square.

I received this problem in a competitive math contest in which the problems were fairly easy to me, but this one has had me puzzled for a couple of days. The other problems in the contest were not too hard to figure out the solution to, so I think that this one has a formula or something of that sort which makes it much easier.

2 Answers2

3

Well, assume $m \in \mathbb{Z}$ and take

$$n^2 - 7 n + 21 - m^2 = 0$$

Using the quadratic formula,

$$n = \frac{7 \pm \sqrt{49 - 4 (21 - m^2)}}{2}$$

Clearly for $n$ to be an integer, the expression $49 - 4 (21 - m^2) = 4 m^2 - 35$ must be a perfect square; i.e., $4 m^2 - 35 = k^2$, where $k \in \mathbb{Z}$. Then $4 m^2 - k^2 = (2 m + k) (2 m - k) = 35$. Since $35 = (5) (7)$, there are only a few cases to check; restricting ourselves (WLOG) to non-negative solutions, we find $(m, k)$ must be $(3, 1)$ or $(9, 17)$. This leaves $n = \frac{7 \pm 1}{2}$ or $n = \frac{7 \pm 17}{2}$. Therefore, $n \in \{ 3, 4, 12 \}$ (note that $-5$ satisfies the equation but is not positive). The answer is $3 + 4 + 12 = \boxed{19}$.

K. Jiang
  • 7,210
  • 1
    Note that $k=2n-7$ and that you can multiply the first equation by $4$ to get $$(2m)^2=4m^2=4(n^2-7n+21)=(2n-7)^2+35.$$ – Servaes May 27 '23 at 15:32
1

For most positive values of $n$ you have $$(n-4)^2<n^2-7n+21<(n-3)^2,$$ and so the quadratic cannot be a perfect square. To make precise what 'for most' means, expand $$n^2-7n+21<(n-3)^2=n^2-6n+9,$$ to find that this holds precisely if $n>12$. Similarly, the other inequality holds for $n>-5$. So it suffices to check whether $n=1,\ldots,12$ yield perfect squares.

Servaes
  • 63,261
  • 7
  • 75
  • 163