5. On graph paper (the side of a cell is 1 cm) a rectangle is drawn, the sides of which lie on the grid lines, with one side being 7 cm shorter than the other. It turned out that it can be cut into several pieces along the grid lines and form a square from them. What can the side of this square be? Find all possible values.
Answer: 6 cm.

Solution. Let the larger side of the rectangle be $k$ cm, where $k>7$, and the side of the resulting square be $n$ cm. Then, from the equality of the areas, we get $k(k-7)=n^{2}$. Since $n<k$, let $n=k-m$, where $m \geqslant 1$. Then $k^{2}-7 k=(k-m)^{2}, k^{2}-7 k=k^{2}-2 m k+m^{2}$, from which $m(2 k-m)=7 k$. Therefore, one of the numbers $m$ or $2 k-m$ is divisible by 7.

If $m=7 s$, then we get $s(2 k-7 s)=k$, from which

$$
k=\frac{7 s^{2}}{2 s-1}=7\left(\frac{s}{2}+\frac{1}{4}+\frac{1}{4(2 s-1)}\right) \quad \Rightarrow \quad 4 k=14 s+7+\frac{7}{2 s-1}
$$

This means that 7 is divisible by $2 s-1$, which is possible only when $s=1$ or $s=4$. In the first case, $m=7, k=7$ and $n=0$, which is impossible. In the second case, we get $m=28, k=16$ and $n=12$.

The case where $2 k-m$ is divisible by 7 reduces to the previous one by substituting $m_{1}=2 k-m, m=$ $2 k-m_{1}$.

Thus, the only possible value of $n$ is 12, with $k=16$. The rectangle $16 \times 9$ can be cut along the grid lines and assembled into a square $12 \times 12$ in many ways.