5. Let $n$ be a natural number greater than 1, and $x$ be a real number.

a) Calculate

$$
S(x, n)=\sum_{\substack{p, q=1 \\ p \neq q}}^{n}(x+p)(x+q)
$$

b) Do there exist integer values of $x$ for which $S(x, n)=0$?
Solution. a) Let's write the given sum in the form

$$
S(x, n)=\sum_{\substack{p, q=1 \\ p \neq q}}^{n}(x+p)(x+q)=\sum_{\substack{p, q=1 \\ p \neq q}}^{n}\left(x^{2}+(p+q) x+p q\right)=A x^{2}+B x+C
$$

where $A, B, C$ are coefficients that need to be determined. Pairs $(p, q)$ such that $p, q \in\{1,2, \ldots, n\}$ and $p \neq q$ have $n^{2}-n$, so $A=n^{2}-n$. To calculate the coefficient $B$, let's arrange all the sums in the table shown in the following diagram:

![](https://cdn.mathpix.com/cropped/2024_06_05_118f91fe8bf1788f2605g-11.jpg?height=400&width=920&top_left_y=468&top_left_x=410)

From this, it is easy to obtain that

$$
\begin{aligned}
B & =2+2 \cdot 3+\ldots+(n-1) n+n(n+1)+(n-1)(n+2)+\ldots+2(2 n-1)+2 n-(2+4+\ldots+2 n) \\
& =(2+2 n)+2(2+2 n)+3(2+2 n)+\ldots+(n-1)(2+2 n)+n(n+1)-2(1+2+\ldots+n) \\
& =2(n+1)(1+2+\ldots+(n-1))+n(n+1)-2 \frac{n(n+1)}{2} \\
& =2(n+1) \frac{(n-1) n}{2}=(n-1) n(n+1)
\end{aligned}
$$

Similarly, using the following table

$$
\begin{array}{r|cccccc}
q \\
n & & & & & & \\
n-1 & n & 2 n & 3 n & \ldots & (n-1) n & n^{2} \\
& n-1 & 2 n-2 & 3 n-3 & \ldots & (n-1)^{2} & (n-1) n \\
3 & \vdots & \vdots & \vdots & & \vdots & \vdots \\
2 & 3 & 6 & 9 & \ldots & 3 n-3 & 3 n \\
1 & 1 & 4 & 6 & \ldots & 2 n-2 & 2 n \\
& 1 & 2 & 3 & \ldots & n-1 & n \\
\hline & 1 & & n-1 & n
\end{array}
$$

in which all products $p q$ are written, we get

$$
\begin{aligned}
C & =(1+2+\ldots+n)+2(1+2+\ldots+n)+\ldots+n(1+2+\ldots+n)-\left(1^{2}+2^{2}+\ldots+n^{2}\right) \\
& =\frac{n(n+1)}{2} \cdot \frac{n(n+1)}{2}-\frac{n(n+1)(2 n+1)}{6}=\frac{1}{12}(n-1) n(n+1)(3 n+2) .
\end{aligned}
$$

Therefore,

$$
S(x, n)=(n-1) n x^{2}+(n-1) n(n+1) x+\frac{1}{12}(n-1) n(n+1)(3 n+2)
$$

b) Solving the equation $S(x, n)=0$ we get

$$
x=\frac{-(n+1) \pm \sqrt{\frac{n+1}{3}}}{2}
$$

and this number will be an integer for integer values of $n$ if and only if $n=3 k^{2}-1, k \in \mathbb{N}$.