# About $142857$: proof that $\;3 \mid 1^n + 4^n + 2^n + 8^n + 5^n + 7^n$

Most of you already know the flabbergasting properties of cyclic numbers. Among these, $142857$ deserves to be the most famous and admired, being (in base $10$) the smallest and the only one without those spoilsport leading zeros. I personally love a couple of elegant features of its digits that aren’t often underlined. Their sequence defines a graceful pattern on a calculator’s keypad:

Another (partially related) feature is that they are exactly all the base-$10$ digits that are not divisible by $3$, each one taken once. Yet when you sum them up you get $1+4+2+8+5+7=27=3^3$, obviously divisible by $3$. I went on to discover that more generally

$$\forall n,\qquad1^n + 4^n + 2^n + 8^n + 5^n + 7^n \equiv 0 \;\pmod 3 .$$

Even if I’m not familiar with modular arithmetic (in the sense that I never really studied it — I’ve learned what I know here and there and I try to use it at my best following my instinct) I think I succeeded proving this equivalence. According to Stack Exchange’s encouragement to answer own questions, I’ll write my proof as an answer below, asking you to check it, improve it, or replace with a better one (in what case I won’t hesitate accepting the new one as best answer). Thank you!

#### Solutions Collecting From Web of "About $142857$: proof that $\;3 \mid 1^n + 4^n + 2^n + 8^n + 5^n + 7^n$"

$$\begin{array}{rcl} 1^n+2^n+4^n+8^n+5^n+7^n &\equiv& 1+(-1)^n+1+(-1)^n+(-1)^n+1&\pmod3 \\ &\equiv& 3\{1+(-1)^n\} \end{array}$$

I’ll look at each addend one at a time.

$1^n$:
$$1^n \equiv 1 \;\pmod 3$$

$4^n$:
\begin{align} 4 &\equiv 1 &\pmod 3\\ 4 \cdot 4 &\equiv 4 \equiv 1 &\pmod 3\\ &\;\;\vdots\\ 4^n &\equiv 1 &\pmod3 \end{align}

$2^n$:
\begin{align} 2 &\equiv 2 &\pmod 3\\ 2 \cdot 2&\equiv 4 \equiv 1 &\pmod 3\\ 2 \cdot 2 \cdot 2 &\equiv 2 &\pmod 3\\ &\;\;\vdots\\ 2^n &\equiv \begin{cases} 2 & \text{if n is odd} \\ 1 & \text{if n is even} \end{cases} &\pmod3 \end{align}
I’d rewrite this in a synthetic way so that in the following I won’t need to examine odd and even cases separately:
$$2^n \equiv 1+(n\bmod 2) \qquad\pmod 3$$

$8^n$:
\begin{align} 8 &\equiv 2 &\pmod 3\\ 8 \cdot 8&\equiv 16 \equiv 1 &\pmod 3\\ 8 \cdot 8 \cdot 8 &\equiv 8 \equiv 2 &\pmod 3\\ &\;\;\vdots\\ 8^n &\equiv \begin{cases} 2 & \text{if n is odd} \\ 1 & \text{if n is even} \end{cases} = 1+(n\bmod 2) &\pmod 3\\ \end{align}

$5^n$:
\begin{align} 5 &\equiv 2 &\pmod 3\\ 5 \cdot 5&\equiv 10 \equiv 1 &\pmod 3\\ 5 \cdot 5 \cdot 5 &\equiv 5 \equiv 2 &\pmod 3\\ &\;\;\vdots\\ 5^n &\equiv \begin{cases} 2 & \text{if n is odd} \\ 1 & \text{if n is even} \end{cases} = 1+(n\bmod 2) &\pmod 3\\ \end{align}

$7^n$:
\begin{align} 7 &\equiv 1 &\pmod 3\\ 7 \cdot 7 &\equiv 7 \equiv 1 &\pmod 3\\ &\;\;\vdots\\ 7^n &\equiv 1 &\pmod3 \end{align}

Now I’m ready to sum them up:

\begin{align} 1^n + 4^n + 2^n + 8^n + 5^n + 7^n \equiv&\\ \equiv\ 1 + 1 + \left[1+(n\bmod 2)\right] + \left[1+(n\bmod 2)\right] + \left[1+(n\bmod 2)\right] + 1 =&\\ =3+3\cdot\left[1+(n\bmod 2)\right]=&\\ =6+3\cdot(n\bmod 2)\equiv& \ 0 \;\pmod 3\\ \end{align}

which is the wanted equivalence.