Proofs using modular arithmetic. In my textbook, it says,

The sum of the cubes of any three consecutive integers is divisible by
$9$

This statement is equivalent to proving,

$(n^3 + (n+1)^3 + (n+2)^3 ) \mod 9 =0$  is true for $n=0,1, \ldots, 8$

Now I understand how the modulo function works but I just don't see how the latter part is the same as the former. Can anyone walk me through it?
Note that, I'm not really looking for the proof, what I am looking for is how the first and the second statement are related.
Follow up question which begs to be asked,
Given some expression of $a \in \mathbb{Z}$, say $P(a)$, are the following 2 statements equivalent?

*

*$n$ divides $P(a), \, \forall a \in \mathbb{Z}$ and for some fixed $n \in \mathbb{N}$


*$P(a) \mod n = 0, \forall a \in \{0,1, \ldots, n-1\}$
Can anyone explain me whether or not the two statements are equivalent? Thanks!
 A: $$ n | P(a) \ \forall \ a\in \mathbb Z \iff P(a) \mod n = 0 \ \forall \ a\in \{0,1,2\dots n-1\}$$ The key here is that if all elements $e$ in this set satisfy this property, then all numbers of the form $e+nk$ for some integer $k$ also satisfy this property, as the $kn$ term gets vanished mod $n$. For instance, $$ n^3 +(n+1)^3 +(n+2)^3 \equiv (n+9k)^3 +(n+9k+1)^3 +(n+9k+2)^3 \pmod 9 $$ because $$(n+9k)^3 = n^3 +9^3k^3 +3n^2(9k) +3(n)(9^2k^2) = n^3 +9(\text{stuff}) $$ and similarly for the other two terms.
A: If $n$ and $m$ are equivalent modulo $9$, then so are $n^3$ and $m^3$. Hence there is no need to try all $n$, but only those that yield different values modulo $9$.
A: $3$ consecutive numbers gives remainders $0,1,-1(i.e 2)$ in some order when divided by $3$. So let $3$ consecutive  numbers be $3k,3k'+1,3k''-1$ in some order. Cubing and adding we get, $(3k)^3+(3k'+1)^3+ (3k''-1)^3= 27k^3+27k'^3+ 9k'^2+ 9k'+1+27k''^3- 9k''^2+ 9k''-1= 9K$
A: 
Given some expression of $a \in \mathbb{Z}$, say $P(a)$, are the following 2 statements equivalent?

*

*$n$ divides $P(a), \, \forall a \in \mathbb{Z}$ and for some fixed $n \in \mathbb{N}$


*$P(a) \bmod n = 0, \forall a \in \{0,1, \ldots, n-1\}$

Yes, let's derive the equivalence step-by-step.
$$\begin{align}
\forall\, a\,\in\, \Bbb Z:&\ \ \ n\,\mid\, P(a)\\[.2em]
\iff \forall\, a\,\in\, \Bbb Z:&\ \ \ 0 = P(a)\bmod n\\[.2em]
\iff \forall\, a\,\in\, \Bbb Z:&\ \ \ 0 = P(\bar a)\bmod n,\,\ \bar a = a\bmod n, \ \rm by\ \color{#C00}{PCR}\\[.2em]
\iff \forall\, \bar a\in[n]\!:&\ \ \ 0 = P(\bar a)\bmod n,\,\ [n] = \{0,1,\ldots,n\!-\!1\}\\[.2em]
\iff \forall\, \bar a\in\Bbb Z_n\!:&\ \ \ 0 = P(\bar a)
\end{align}\qquad$$
where we employed the following Polynomial Congruence Rule $\, =\rm\color{#C00}{PCR}$
$\quad \bmod n\!:\ a\equiv \bar a\,\Rightarrow\, P(a)\equiv P(\bar a),\ $ for $\,P(x)\,$ any polynomial with integer coef's
Generally, given any expression composed of sums and products of integers, its value  $\bmod n\,$ is unchanged when we replace the arguments of the sums and products by congruent arguments.  In particular this is true if we replace them by their least nonnegative reps $\, a\mapsto a\bmod n$.
Above we could replace the standard residue system $\,[n] = 0,1,2,\ldots\,n\!-\!1\,$ by any complete system of residues $\cal R,\,$ i.e. any set of integers such that every integer is congruent to exactly one $\,r\in \cal R.\,$ Then verifying that every $\,r\in\cal R\,$ is a root is sufficient to guarantee that every integer is a root, since every integer is congruent to some normal rep $\,r\in\cal R,\,$ i.e. we have $\,n\equiv r\in {\cal R}\,\Rightarrow\, P(n)\equiv P(r)\equiv 0,\,$ by $\,\rm\color{#c00}{PCR}$
A "normal" rep in $\cal R$ can be view as "name' or "label" for the entire set of integers equivalent to it, i.e. $\,r\mapsto [r]_n = r + n\Bbb Z,\,$ the set of all integers $\equiv r\pmod{\!n}.\,$ Then the congruence sum and product rules imply that addition and multiplication is well-defined on these classes by the rules $[a]+[b] = [a+b],\,$ $[a]*[b] = [a*b].\,$ In turn this implies that the arithmetical (ring) laws of $\,\Bbb Z\,$ are inherited by the classes with these operations, so they form a new system of numbers (ring) $\,\Bbb Z_n\,$ sharing many of the same properties of the ring of integers - so we can reuse our well-honed integer arithmetic intuition in this new modular number system. In particular, viewed in the ring $\,\Bbb Z_n\,$ your statement simplifies to the final form in the string of equivalences, viz. $\,\forall\,\bar a \in \Bbb Z_n\!:\ P(\bar a) = 0,\,$ i.e. every element of $\,\Bbb Z_n\,$ is a root of $\,P\,$ (here $P$ is viewed as a polynomial over $\,\Bbb Z_n\,$ by mapping its integer coef's into $\,\Bbb Z_n\,$ via $\,p_i\mapsto \bar p_i = [p_i]_n)$.
