TITLE: Why is the function $f(x)=x^3 \pmod{10}$ periodic with this strange property?
QUESTION [6 upvotes]: I've noticed that the function $f(x)=x^3  \pmod{10}$ is periodic. For example, listing mod(x^3,10) we get:
0,1,8,7,4,5,6,3,2,9,0,1,8,7,4,5,6,3,2,9,0,1,8,7,4,5,6,3,2,9,0,1,8,7,4,5,6,3,2,9,0,1,8,7,4,5,6,3,2,9

What's weird, though, is that the period contains all numbers from the image of the function exactly once. Why does that happen?

REPLY [2 votes]: Oblique to the original question, but it may help if you want to explore further.  
The integers modulo $10$ form a ring.  This is true whatever the modulus.  Basically that means that addition, subtraction, and multiplication work properly, including the distributive property.  There may be $ab=0$ without $a=0$ or $b=0$.  Being a ring means that $x^3 \pmod {10}=(x \pmod {10})^3 \pmod {10}$ or, informally, you can strip off all the digits except the units before cubing, then strip them off again after.  What you have observed is that the function $x^3 \pmod {10}$ is injective.