4. In a number system with base $r$ ( $r \leqslant 100$ ), a natural number $x$ is a two-digit number with identical digits. It turns out that the $r$-ary representation of the number $x^{2}$ is four-digit, and the extreme digits are the same, while the middle ones are zero. For which $r$ is this possible?
Answer: $r=2$ or $r=23$.

Solution. Let's write the condition as $a^{2}(1+r)^{2}=b\left(1+r^{3}\right)$, where $a, b-r$ are digits. By canceling out $1+r$, we get

$$
a^{2}(1+r)=b\left(1-r+r^{2}\right)=b((1+r)(r-2)+3)
$$

Note that the GCD $(1+r,(1+r)(r-2)+3)$ is 1 or 3. In the first case, $b \vdots (r+1)$, which is impossible since $0<b \leqslant r-1$. Therefore, $(1+r) \vdots 3$ and $b \vdots \frac{1+r}{3}$. Then $b=\frac{k(1+r)}{3}$, where $k$ is 1 or 2. Let $1+r=3s$. From $(*)$

$$
3 a^{2} s=k s(3 s(3 s-3)+3) \Longleftrightarrow a^{2}=k(3 s(s-1)+1)
$$

Since $s(s-1)$ is even, for $k=2$ we get $a^{2} \bmod 4=2$, which is impossible. Therefore, $k=1$ and

$$
4 a^{2}=3\left(4 s^{2}-4 s\right)+4=3(2 s-1)^{2}+1 \Longleftrightarrow(2 a-1)(2 a+1)=3(2 s-1)^{2}
$$

The numbers $2 a-1$ and $2 a+1$ are coprime since they are odd and differ by 2. Moreover, one of these numbers is divisible by 3. Therefore, $\frac{2 a-1}{3}$ and $2 a+1$ or $\frac{2 a+1}{3}$ and $2 a-1$ are perfect squares. Let's consider two cases.

1) $2 a-1=3 m^{2}$. Then the number $3 m^{2}+2$ will be a perfect square. But this is impossible since $\left(3 m^{2}+2\right) \bmod 3=2$, and the remainder of the square of a natural number when divided by 3 can only be 0 or 1.
2) $2 a+1=3 m^{2}$. Since the number $2 a+1$ is odd and does not exceed 199, it can take the values $3,27,75,147$. In the first case

$$
m=1, a=1,2 a-1=1,2 s-1=m \sqrt{2 a-1}=1, \quad s=1, \quad r=3 s-1=2, b=1
$$

which satisfies the condition since $11_{2}^{2}=1001_{2}$. In the second case

$$
m=3, \quad a=13,2 a-1=25,2 s-1=m \sqrt{2 a-1}=15, \quad s=8, \quad r=3 s-1=23, \quad b=8
$$

which satisfies the condition since $D D_{23}^{2}=8008_{23}$. Thus, $r=2$ and $r=23$ are suitable. The last two values do not work since $2 a-1$ will be 73 or 145, and these numbers are not perfect squares.