4. The board has the number 5555 written in an even base $r$ ($r \geqslant 18$). Petya found out that the $r$-ary representation of $x^{2}$ is an eight-digit palindrome, where the difference between the fourth and third digits is 2. (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=24$.

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 $d-c=2$ and

$$
25(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 following 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, by $(*)$

$$
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-b-c+d| \leqslant 2(r-1)<2 r<r^{2}+1
$$

Thus, $b-a=d-c=2$.

2) Since $r^{n} \equiv 1(\bmod (r-1))$ for any natural $n$, from $(*)$ and 1$)$ it follows that

$$
25 \cdot 16 \equiv 2(a+b+c+d)=4(b+c)(\bmod (r-1))
$$

Since $r-1$ is odd, $r-1$ divides the number $100-(b+c)$.

3) For any natural $n$

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

The right-hand side of $(*)$ is divisible by $(r+1)^{2}$, hence

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

Thus, $r+1$ divides the number

$$
7 a-5 b+3 c-d=7(b-2)-5 b+3 c-(c+2)=2(b+c)-16
$$

Then $b+c-8 \vdots(r+1)$ due to the oddness of $r+1$. Therefore, $b+c=8$ or $b+c=8+r+1$. In the second case,

$$
0 \equiv 92-(r+1) \equiv 90(\bmod (r-1))
$$

Since $r$ is even and $r-1 \geqslant 17$, we get $r=46$. Then $a=25$ and $b=27$, which is impossible, as $b=50 \bmod 46=4$. Thus, $b+c=8$. By 2$) 92 \vdots(r-1)$, hence $r=24$.

Remark. If $b+c=8$ and $r=24$, then

$$
a=25 \bmod 24=1, \quad b=a+2=3, \quad c=8-b=5, \quad d=c+2=7
$$

The equality $5555_{24}^{2}=13577531_{24}$ is verified by direct computation.