In the book, Elements of programming CASE ANALYSIS has been listed as one of the approaches to solve a problem.
As an example, the book states that
for all n , n^3 mod 9 would either be 0,1,8 and even splits this problem into following cases where n belongs to the following category
- n = 3m
- n = 3m + 1
- n = 3m +2
Based on the way that this has been glossed over in the book, it seems like a trivial concept. But i couldn't establish the relation between n^3 and all the three cases which are listed above. They seems to be (at least to my understanding) the numbers which are similar to n = num mod 3
But how does it relate to proving n^3 mod 9 is 0,1 and 8 and how these three cases would suffice to prove the problem statement
Let $n$ be a natural number. Then $n$ can be of the form: $n=3k, n=3k+1,n=3k+2$. Those are the only three options for $n$, either it's divisible by 3,has a remainder 1 or a remainder 2.
So suppose $n=3k$. then $n^3 = (3k)^3= 27k^3=0 (mod 9)$ In that case, $n^3$ is 0 (mod 9).
Now suppose, $n=3k+1$. then $n^3 = (3k+1)^3= 27 k^3 + 27 k^2 + 9 k + 1=1 (mod 9)$ In that case, $n^3$ is 1 (mod 9).
And finally, suppose $n=3k+2$. then $n^3 = (3k+2)^3=27 k^3 + 54 k^2 + 36 k + 8=8 (mod 9)$ In that case, $n^3$ is 8 (mod 9). And since we did all the cases, the mod 9 of a cube is either 0, 1 or 8. Hope this helps!