[Math] Why is there a pattern to the last digits of square numbers

decimal-expansionelementary-number-theorymodular arithmeticsquare-numbers

I was programming and I realized that the last digit of all the integer numbers squared end in $ 0, 1, 4, 5, 6,$ or $ 9 $.

And in addition, the numbers that end in $ 1, 4, 9, 6 $ are repeated twice as many times as the numbers that end in $ 0, 5$

I checked the numbers from $1$ to $1000$, and the results are:

$1.$ The numbers on the left are the last digit of each digit squared.

$2.$ The numbers on the right are the number of times that the last digit is repeated.

$$
\begin{array}{cc}
0: &100, \\
1: &200, \\
4: &200, \\
5: &100, \\
6: &200, \\
9: &200
\end{array}
$$

So, why does this happen? What is the property that all integers have?

Best Answer

The answer to this question is a bit less profound than you might hope. To see why, first note that the last digit of the square of any natural number only depends on the number's last digit - any other digits represent powers of 10 and do not make any difference to the last digit of the square.

So the problem amounts to working out the last digit of the squares of single digit numbers (and 10, if we don't consider 0 a natural number). They are:

  1. 1
  2. 4
  3. 9
  4. 6
  5. 5
  6. 6
  7. 9
  8. 4
  9. 1
  10. 0

The relative frequencies of these last digits here explain why they take up the proportions of square numbers that you observe.