Problem 12. Determine all natural numbers $n$ for which there exists some natural number $m$ with the following properties:

- $m$ has at least two digits (in base 10), all are distinct and none is 0.
- $m$ is a multiple of $n$ and any rearrangement of its digits results in a multiple of $n$.
Solution. Note that $n=1,3,9$ work because in these cases the divisibility criterion is that the sum of the digits is a multiple of $n$, and taking $m=18$ is sufficient. For any other case, consider that $m$ exists and has the rightmost digit as $x$ and then a $y$.

Then, by permuting these two digits, we will have that as the congruence modulo $n$ is preserved, $9(x-y)$ must be a multiple of $n$. This means that $x$ is congruent to $y$ modulo $n / \operatorname{gcd}(9, n)$. If $n$ is not a multiple of $9$, $x$ is congruent to $y$ and it must be that $n \leq 8$. For $n=2,4$, take $m=48$. If $n=8$, all its digits must be even, but this is incompatible with $x-y$ being a multiple of 8 and $1 \leq x, y \leq 9$.

Now suppose that $n$ is a multiple of 3 but not of 9. If $n=6$, all the digits are also even, leaving the only option $\{x, y\}=\{2,8\}$. But 28 is not a multiple of 6, so there would have to be more digits, which can only be taken from 4 and 6; but none of these numbers are multiples of $6: 2+8+4,2+8+4,2+8+6,2+8+4+6$. Therefore, $n$ would have to be odd, and since $x$ is congruent to $y$ modulo $n / 3$, it would have to be that $n \leq 24$, and the only options we haven't seen yet are $n=15$ and $n=21$. $n=15$ cannot be because all the digits would be multiples of 5. If $n=21$, $\{x, y\}=\{1,8\}$ or $\{x, y\}=\{2,9\}$, so the number has a third digit $z$ and repeating the analysis it turns out that since 90 is not a multiple of $7$, $y-z$ is a multiple of 7, so $x$ would be equal to $z$.

The only case left is a multiple of 9, and in that case $x, y$ are congruent modulo $n / 9$; then it happens that $n \leq 81$ and $n$ is odd as stated before; it cannot be a multiple of 5 or 7 either; so we are left with the cases $n=27$, 81. If we rule out $n=27$, we will be done. $x, y$ are congruent modulo 3; in general, all the digits are congruent modulo 3 so we can only have 3 digits; to be a multiple of 9, all three digits must be multiples of 3 so $m$ would have to be some permutation of 369, but we simply observe that 369 is not a multiple of 27. Therefore, $n$ can be $1,2,3,4,9$.