Problem 4. (10 points) In a row, 2018 digits are written consecutively. It is known that in this row, every two-digit number formed by two adjacent digits (in the order they are written) is divisible by 17 or 23. The last digit in this row is 5. What is the first digit in the row? Provide a justified answer.

#
# Solution:

All two-digit numbers divisible by 17 or 23:

$$
\begin{aligned}
& 17,34,51,68,85 \\
& 23,46,69,92
\end{aligned}
$$

The following diagram shows with arrows which digit can follow which in the row:

$$
\begin{aligned}
& 1 \rightarrow 7 \quad 9 \rightarrow 2 \rightarrow 3 \\
& \uparrow \quad \uparrow \\
& 5 \leftarrow 8 \longleftarrow 6 \leftarrow 4
\end{aligned}
$$

Traversing the digits in the row from right to left corresponds to moving against the direction of the arrows. If in this diagram we take steps against the direction of the arrows, starting from the digit 5, we end up at 6 in two steps, and then we will be moving in a cycle, landing back at 6 every 5 steps.

Since \(2017 = 2 + 5 \cdot 403\), the first digit will be 6.

Answer. 6.