4. The number $x=9999$ is written on the board in an even base $r$. Vasya found out that the $r$-ary representation of $x^{2}$ is an eight-digit palindrome, where the sum of the second and third digits is 24. (A palindrome is a number that reads the same from left to right and from right to left). For which $r$ is this possible?
Answer: $r=26$.

Solution. Let's agree to write $u \equiv v(\bmod w)$ if $(u-v) \vdots w$. According to the condition, there exist such $r$-ary digits $a, b, c, d$ that $b+c=24$ and

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

Let's make some observations.

1) Since $r^{6} \equiv-1\left(\bmod \left(r^{2}+1\right)\right)$, the equalities hold

$$
r^{7}+1 \equiv 1-r\left(\bmod \left(r^{2}+1\right)\right) \quad \text { and } \quad r^{6}+r \equiv r-1\left(\bmod \left(r^{2}+1\right)\right)
$$

Moreover, $r^{4} \equiv 1\left(\bmod \left(r^{2}+1\right)\right)$, hence

$$
r^{5}+r^{2} \equiv r-1\left(\bmod \left(r^{2}+1\right)\right) \quad \text { and } \quad r^{4}+r^{3} \equiv 1-r\left(\bmod \left(r^{2}+1\right)\right)
$$

Then, due to $(*)$

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

Note that $r^{2}+1+(1-r)(r+1)=2$, and the numbers $1-r$ and $r^{2}+1$ are odd. Therefore, they are coprime, which implies $a-b-c+d \vdots\left(r^{2}+1\right)$. But

$$
|(a+d)-(b+c)| \leqslant 2(r-1)9$, so $r$ can only take the values $16,26,76$. In the case of $r=16$, considering 1)

$$
a=81 \bmod 16=1 \quad \text { and } \quad d=24-a=23>r
$$

which is impossible. If $r=76$, then $a=81 \bmod 76=5$, from which the leading digit of $x^{2}$ is 5. But this is impossible, since $9999_{76}^{2}<10^{2} \cdot 76^{6}<2 \cdot 76^{7}$. Therefore, $r=26$.

Remark. If $r=26$, then due to 1)

$a=81 \bmod 26=3, \quad d=24-a=21=L_{26}, \quad b=\left(81 \cdot 2+\left[\frac{81}{26}\right]\right) \quad \bmod 26=9, \quad c=24-b=15=F_{26}$.

The equality $9999_{26}^{2}=39 F L L F 93_{26}$ is verified by direct computation.