4. Petya wrote down $n$ consecutive two-digit numbers $(n \geqslant 2)$ in a row on the board, the first of which does not contain the digit 4, and the last one does not contain the digit 7. Vasya thought that this was the decimal representation of a natural number $x$, and he factored $x$ into prime factors. It turned out that there were only two of them and they differ by 4. What is written on the board?
Answer: 2021.

Solution. Let $a$ and $b$ be the prime divisors of $x$, with $b=a+4$. The pairs of the last digits of $a$ and $b$ can be $(3,7),(7,1),(9,3)$. Since $x$ cannot end in 7, only the first case is possible. Then the number $y=\frac{a+b}{2}$ ends in 5 and, therefore, has the form $y=10 m+5$. From this,

$$
y^{2} \bmod 100=25\left(4 m^{2}+4 m+1\right) \bmod 100=25
$$

which means $y^{2}$ ends in 25. Therefore, $x=y^{2}-4$ ends in 21, and 21 is the last number written by Petya. Thus, $x$ can take one of the following values:

$$
2021,192021,18192021, \ldots, 1011 \ldots 2021
$$

The first one fits, since $2021=43 \cdot 47$. Note that $x$ is not divisible by 3 and 11 (otherwise, $x \leqslant 3 \cdot(3+4)=21$ and $x \leqslant 11 \cdot(11+4)=165$ respectively). According to the first condition, we discard numbers starting with $10,12,13,15,16,18,19$, and according to the second condition, the number starting with 11 (the sums of its digits at even and odd positions differ by 33). The number $x$ cannot start with 14 by the condition. If $x=1718192021$, then

$$
y^{2}=x+4=1718192025
$$

But the right-hand side is divisible by 11 and not by 121, and therefore cannot be a perfect square.