4. A natural number $x$ in a base $r$ system ( $r \leqslant 36$ ) has the form $\overline{p p q q}$, and $2 q=5 p$. It turns out that the $r$-ary representation of the number $x^{2}$ is a seven-digit palindrome with a zero middle digit. (A palindrome is a number that reads the same from left to right and from right to left). Find the sum of the $r$-ary digits of the number $x^{2}$.
Answer: 36.

Solution. Let's agree to write $u \equiv v(\bmod w)$ if $(u-v) \vdots w$. Let $p=2 s, q=5 s$. Then $x=\overline{p p q q}_{r}=\left(p r^{2}+q\right)(r+1)=s\left(2 r^{2}+5\right)(r+1)$. From the condition on $x^{2}$, we get the equality

$$
s^{2}\left(2 r^{2}+5\right)^{2}\left(r^{2}+2 r+1\right)=a\left(1+r^{6}\right)+b\left(r+r^{5}\right)+c\left(r^{2}+r^{4}\right)
$$

where $a, b, c$ are some $r$-ary digits. Let's make two observations.

1) For any natural $n$

$$
r^{n}=(1+r-1)^{n} \equiv(-1)^{n}(1-n(1+r))\left(\bmod (1+r)^{2}\right)
$$

The right side of $(*)$ is divisible by $(1+r)^{2}$, from which

$$
0 \equiv a(2-6(1+r))-b(2-6(1+r))+c(2-6(1+r))=2(1-3(1+r))(a-b+c)\left(\bmod (1+r)^{2}\right)
$$

Since $1-3(1+r)$ is coprime with $(1+r)^{2}$, $2(a-b+c)$ is divisible by $(1+r)^{2}$. But this number lies in the interval $(-2 r, 4 r) \subset\left(-(1+r)^{2},(1+r)^{2}\right)$, hence $b=a+c$.

2) Equate the remainders of the left and right sides of $(*)$ when divided by $1+r^{2}$:

$$
18 s^{2} r \equiv b r\left(1+r^{4}\right) \equiv 2 b r\left(\bmod \left(1+r^{2}\right)\right)
$$

Since $r$ is coprime with $1+r^{2}$, $2\left(9 s^{2}-b\right)$ is divisible by $1+r^{2}$. Note that $4 s^{2} \leqslant r-1$, otherwise the number $x^{2}$ will be eight-digit. In addition, $r \geqslant 5 s+1 \geqslant 6$. Therefore

$$
2\left(9 s^{2}-b\right)-2 r>-1-r^{2}
$$

Thus, $b=9 s^{2}$.

Since $b$ is an $r$-ary digit, from 2) it follows that $9 s^{2} \leqslant r-1$. Since $s>0$, we get $s=1$ and $b=9$. By 1), the sum of the digits of $x^{2}$ is $2(a+b+c)=4 b=36$.

Remark. It can be verified by direct calculation that $2255_{21}^{2}=4950594_{21}$. Thus, the situation described in the problem is realized.