5. Find all four-digit numbers n that have the following three properties: $V$ in the representation of the number n there are two different digits, each twice. The number n is divisible by seven. The number that results from reversing the order of the digits of the number n is also four-digit and divisible by seven.
SOLUTION. In the solution, we will denote the number that results from reversing the order of the digits of the number $n$ as $\bar{n}$. We will distinguish three cases.

(i) The number $n$ has the form $a a b b$, where $a, b$ are different digits. Thus, $n=1100 a+11 b$ and $\bar{n}=1100 b+11 a$. The number 7 must divide both $n$ and $\bar{n}$, and thus also their difference $n-\bar{n}=1089(a-b)$ and their sum $n+\bar{n}=1111(a+b)$. Since neither the number 1089 nor the number 1111 are multiples of seven and seven is a prime number, $7 \mid a-b$ and $7 \mid a+b$. Using the same reasoning again, we see that $7 \mid (a-b)+(a+b)=2a$ and $7 \mid (a+b)-(a-b)=2b$, so $7 \mid a$ and $7 \mid b$, or $a, b \in\{0,7\}$. The digits $a, b$ are mutually different, so one of them must be 0. But then one of the numbers $a a b b, b b a a$ is not a four-digit number. The sought number $n$ therefore cannot be of the given form.

(ii) The number $n$ has the form $a b a b$. Then $7 \mid n=1010 a+101 b$ and also $7 \mid \bar{n}=1010 b+101 a$. Similarly to the previous case, we deduce that $7 \mid n-\bar{n}=909(a-b)$ and $7 \mid n+\bar{n}=$ $=1111(a+b)$, and for the same reasons as in the previous case, we find that $7 \mid a$, $7 \mid b$. One of the digits would therefore have to be 0. The number $n$ thus cannot be of the form $a b a b$.
(iii) The number $n$ has the form $a b b a$. Then reversing the order of the digits results in the same number, so we have only one condition $7 \mid 1001 a+110 b$. Since $7 \mid 1001$ and $7 \nmid 110$, this condition is equivalent to the condition $7 \mid b$. Therefore, $b \in\{0,7\}$, $a \in\{1,2, \ldots, 9\}, a \neq b$. Thus, 17 numbers that satisfy the above conditions are: 1001, $2002,3003,4004,5005$, $6006,7007,8008,9009,1771,2772,3773,4774,5775,6776,8778,9779$.

## GUIDING PROBLEMS: