The set $M$ consists of all 7-digit positive integers that (in decimal notation) contain each of the digits 1, 3, 4, 6, 7, 8, and 9 exactly once.

(a) Determine the smallest positive difference $d$ between two numbers in $M$.

(b) How many pairs $(x, y)$ with $x$ and $y$ from $M$ are there such that $x-y=d$?

Answer. a) The smallest possible difference is 9. b) There are 480 such number pairs.
a) All numbers in $M$ have the digit sum $1+3+4+6+7+8+9=38$, so they are congruent to 2 modulo 9. Therefore, the difference $d$ is divisible by 9, which implies $d \geq 9$. For $x=1346798$ and $y=1346789$, we indeed have $x-y=9$, so $d=9$ is the smallest possible difference.

b) From $x=y+9$, the following possibilities for the units digits arise:

| Units digit of $y$ | 1 | 3 | 4 | 6 | 7 | 8 | 9 |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| Units digit of $x$ | - | - | 3 | - | 6 | 7 | 8 |

Due to the carry, the tens digit of $x$ must be 1 greater than the tens digit of $y$, otherwise the two numbers must be identical. This means that $y$ ends in 34, 67, 78, or 89, and in $x$ these two digits are swapped, so $x$ ends in 43, 76, 87, or 98. Therefore, there are 4 possibilities for the last two digits of $y$ and $5! = 120$ possibilities for the digits before them. Thus, there are 480 such pairs.

(Gerhard Kirchner, Gottfried Perz)