Divisibility by n for 3- digit number

$\newcommand{\d}[1]{\overline{#1}}$ $\newcommand{\t}[1]{\mathrm{\underline{\large{#1}}}}$$\color{red}{\t{Introduction}}$

As Greg mentions in the comments, we can make significant improvements. Let $P = x^3+y^3+z^3 - 3xyz$ for $x,y,z$ in context. For $\d{xyz}$ a number, we refer to both $\d{yzx},\d{zxy}$ as its cyclic counterparts or cyclic permutations. I am sure you can generalize this to $m$ digits, which I require only for the last extra section.

$\color{orange}{\t{\gcd\{n,x,y,z\} = 1 \ WLOG}}$

Indeed, suppose that we proved the statement for the case $\gcd(n,x,y,z) = 1$. Then, for $\gcd(n,x,y,z)=d>1$, we may consider the statement for $\frac{n}d, \frac xd,\frac yd,\frac zd$ : note that $\frac nd$ will still divide each of the cyclic counterparts of $\d{\frac xd\frac yd\frac zd}$, so by the statement , $\frac{x^3+y^3+z^3-3xyz}{d^3}$ an integer multiple of $\frac nd$, which implies that $x^3+y^3+z^3-3xyz$ is an integer multiple of $n$.

$\color{fuchsia}{\t{n\ divides \ 999}}$

Now, suppose that $\gcd(n,x,y,z) =\gcd(n,\gcd(x,y,z)) = 1$. Note that $n$ divides $10\d{xyz} - \d{yzx} = 999x$, and similarly $n$ divides $999y$ and $999z$.

Now, by Bezout's theorem, there is an integer linear combination of $x,y,z$ given by $ax+by+cz$ which equals $\gcd(x,y,z)$. Then $n$ divides $999(ax+by+cz) = 999\gcd(x,y,z)$ implying that $n$ divides $999$ by our assumption. Thus, we may restrict ourselves to divisors of $999$.

$\color{purple}{\t{The\ obvious\ cases}}$

The divisors of $999$ are : $1,3,9,27,37,111,333,999$.

For $1$ the statement is obvious. For each of $999,333,111$, if $\d{xyz}$ is a multiple then $x=y=z$ so $P=0$.

For $3,9$ the statement is clear , because $\d{xyz}$ is a multiple of $3$ or $9$ if and only if $x+y+z$ is , respectively (follows from a divisibility test for $3$ and $9$ : take the sum of digits etc.), and $P$ is an integer multiple of $x+y+z$. Thus, we are left with just $27$ and $37$. The techniques for these two are somewhat different.

$\color{grey}{\t{The \ case\ n=37}}$

Let $n=37$.

We know that $\d{xyz}$ and all its cyclic permutations are multiples of $37$. Let us pick the cyclic permutation that has the lowest unit digit i.e. with $z\leq x$ and $z \leq y$. For example, in the family $592,925,259$ we choose $592$, so that $x=5,y=9,z=2$. So we assume $z\leq x , z \leq y$.

Since $37 \times 3 = 111$, we can subtract $1$ from each digit of a ($3$-digit) multiple of $37$ and we will still get a multiple of $37$. For example, from $592$ we get $481$ which is still a multiple of $37$. In algebraic terms , we get that $\d{(x-1)(y-1)(z-1)}$ is also a multiple of $37$ (this is the number with digits $(x-1)$,$(y-1)$,$(z-1)$ in that order). Going like this $z$ times, we get that $\d{(x-z)(y-z)0}$ is a multiple of $37$ i.e. $\d{(x-z)(y-z)}$ is an at most (since $x-z=0$ is possible) two digit multiple of $37$.

For example, starting from $592$, we get to $481$ then to $370$. Since $592$ is a multiple of $37$, so is $370$ and therefore so is $37$. To take another example, take $962 = 37 \times 26$, subtracting one from each digit gives $851$ and then $740$. So $740$ is a multiple of $37$, hence $74$ is a multiple of $37$.

The only (at most) two digit multiples of $37$ are $0,37,74$. So, we must have that $\d{(x-z)(y-z)} = 0,37,74$. This gives three cases : $x=y=z$, $x-z=3,y-z=7$ and $x-z=7,y-z=4$.

Now if $x=y=z$ then $P = 0$.

If $x-z=3,y-z = 7$ then $x=z+3,y=z+7$ so we have : $P = (z+3)^3+(z+7)^3+ z^3 - 3z(z+3)(z+7) = 37(3z+10)$ is a multiple of $37$.

If $x-z=7,y-z = 4$ then $x=z+7,y=z+4$ so we have : $P = (z+7)^3+(z+4)^3+z^3 - 3z(z+4)(z+7) = 37(3z+11)$ is a multiple of $37$.

Thus, $n=37$ works out.

$\color{green}{\t{The\ case\ n=27}}$

For $27$ the task can be accomplished from the factorization $$P = \frac 12(x+y+z)((x-y)^2+(y-z)^2+(z-x)^2)$$ Note that the $\frac 12$ is redundant, we only need to prove that $27$ divides $2P$.

Now, $9$ divides $x+y+z$ from the divisibility rules for $9$, so we only need to prove that $3$ divides $x^2+y^2+z^2 -xy-yz-xz$ since then $27 = 3 \times 9$ will divide the product of these. Recall that $3$ divides $x+y+z$, but then: $$ x^2+y^2+z^2 -xy-yz-xz = (x^2+y^2+z^2 +2xy+2yz+2xz) - 3(xy+yz+zx) \\ = (x+y+z)^2 - 3(xy+yz+zx) $$

which is a multiple of $3$. Hence, we are done.


$\color{#AB4}{\textbf{Sidenote, not related}}$

All the divisors of $999$ have a property, one that I interestingly had a crush on some fourteen years ago, because I'd discovered some generalization to $n$ digits as well :

For $n$ a divisor of $999$, let $\d{xyz}$ be a multiple of $n$. Then $\d{yzx},\d{zxy}$ are also multiples of $n$.

That is, if one of these cyclic permutations is a multiple of $n$ then the rest of them all are. This generalizes :

For $n$ a divisor of $10^m-1$ and any $m$ digit multiple of $n$ , any cyclic permutation of the digits of $m$ (while retaining leading zeros) results in a number which is also a multiple of $n$.

For example, $271 | 99999$, so qualifies. To generate free multiples of $271$ (this was pastime in school, if you like) we have $271|27100$ and we would get $271|10027$ and $271|71002$ for free.

I leave the above as an exercise.