# Why are the last two digits of a perfect square never both odd?

Earlier today, I took a test with a question related to the last two digits of perfect squares.

I wrote out all of these digits pairs up to $20^2$.

I noticed an interesting property, and when I got home I wrote a script to test it. Sure enough, my program failed before it was able to find a square where the last two digits are both odd.

Why is this?

Is this always true, or is the rule broken at incredibly large values?

• do you know about modular arithmetic ? that might be a starting place. – user451844 Aug 19 '17 at 0:51
• The last two digit of a number is the number modulus $100$ Talking about squares the last two digits are cyclical. They repeat every 50 squares from $0$ to $49$ or from $10^9 + 2017$ to $10^9 + 2017 + 49$ they are always the following $00,\;01,\;04,\;09,\;16,\;25,\;36,\;49,\;64,\;81,\;00,\;21,\;44,\;69,\;96,\;25,\;56,\;89,\;24,\;61,\;00,\;41,\;84,\;29,\;76,\;25,\;76,\;29,\;84,\;41,\;00,\;61,\;24,\;89,\;56,\;25,\;96,\;69,\;44,\;21,\;00,\;81,\;64,\;49,\;36,\;25,\;16,\;09,\;04,\;01$ and there is never a combination of two odd digits. – Raffaele Aug 19 '17 at 14:39
• Not only, but if a number does not end with one of the following pair of digits it cannot be a perfect square $00,\; 01,\; 04,\; 09,\; 16,\; 21,\; 24,\; 25,\; 29,\; 36,\; 41,\; 44,\; \\ 49,\; 56,\; 61,\; 64,\; 69,\; 76,\; 81,\; 84,\; 89,\; 96$ – Raffaele Aug 19 '17 at 14:39
• You can also note that the last two digits of squares from 0 to 25 are the same as from 50 to 25 so it is both cyclical and symetrical :) – Rafalon Aug 20 '17 at 9:21
• @Raffaele Sadly if you'd made that into an answer it probably would have earned you a decent chunk of rep and might have been the accepted answer. – Pharap Aug 20 '17 at 16:24

Taking the last two digits of a number is equivalent to taking the number $\bmod 100$. You can write a large number as $100a+10b+c$ where $b$ and $c$ are the last two digits and $a$ is everything else. Then $(100a+10b+c)^2=10000a^2+2000ab+200ac+100b^2+20bc+c^2$. The first four terms all have a factor $100$ and cannot contribute to the last two digits of the square. The term $20bc$ can only contribute an even number to the tens place, so cannot change the result. To have the last digit of the square odd we must have $c$ odd. We then only have to look at the squares of the odd digits to see if we can find one that squares to two odd digits. If we check the five of them, none do and we are done.

• Ah, it's so obvious in hindsight. Although, I suppose most problems like this are. Thanks! – Pavel Aug 19 '17 at 1:00

Others have commented on the trial method. Just to note that $3^2$ in base $8$ is $11_8$ which has two odd digits. This is an example to show that the observation here is not a trivial one.

But we can also note that $(2m+1)^2=8\cdot \frac {m(m+1)}2+1=8n+1$ so an odd square leaves remainder $1$ when divided by $8$.

The final odd digits of squares can be $1,5,9$ so odd squares are $10p+4r+1$ with $r=0,1,2$. $10p+4r$ must be divisible by $8$ and hence by $4$, so $p$ must be even.

In the spirit of experimentation, the last two digits of the squares of numbers obtained by adding the column header to the row header:

$$\begin {array}{c|ccc} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\ \hline 0 & 00 & 01 & 04 & 09 & 16 & 25 & 36 & 49 & 64 & 81\\ 10 & 00 & 21 & 44 & 69 & 96 & 25 & 56 & 89 & 24 & 61\\ 20 & 00 & 41 & 84 & 29 & 76 & 25 & 76 & 29 & 84 & 41\\ 30 & 00 & 61 & 24 & 89 & 56 & 25 & 96 & 69 & 44 & 21\\ 40 & 00 & 81 & 64 & 49 & 36 & 25 & 16 & 09 & 04 & 01\\ 50 & 00 & 01 & 04 & 09 & 16 & 25 & 36 & 49 & 64 & 81\\ 60 & 00 & 21 & 44 & 69 & 96 & 25 & 56 & 89 & 24 & 61\\ 70 & 00 & 41 & 84 & 29 & 76 & 25 & 76 & 29 & 84 & 41\\ 80 & 00 & 61 & 24 & 89 & 56 & 25 & 96 & 69 & 44 & 21\\ 90 & 00 & 81 & 64 & 49 & 36 & 25 & 16 & 09 & 04 & 01\\ 100 & 00 & 01 & 04 & 09 & 16 & 25 & 36 & 49 & 64 & 81\\ 110 & 00 & 21 & 44 & 69 & 96 & 25 & 56 & 89 & 24 & 61\\ 120 & 00 & 41 & 84 & 29 & 76 & 25 & 76 & 29 & 84 & 41\\ \end{array}$$

The patterns are clear, after which the search for a reason for such patterns is well given by the answer of @RossMillikan - you can see that the parity of both final digits of the square is entirely dependent on the final digit of the number that you square.

As a hint, consider what determines the last two digits of a multiplication. Do you remember doing multiplication by hand? If you have square a ten digit number, do all the digits matter when considering just the last two digits of the answer? You will realize that you can put a bound on the number of squares you need to check before you can prove the assertion you are making for all n

• In fact more than enough values of n has been checked (within $20^2$) to see that this result is true. Question is, how does one know enough values have been checked? – Jihoon Kang Aug 19 '17 at 1:02
• That's right - a lazy bound would be checking with a computer all two digit squares, as you know that in a 3 digit number, the hundreds digit will not impact on the final two digits in the multiplication (the same for larger numbers). Obviously you can get sharper than that, as the other answer showed. I was just pointing out that you can very easily come up with a lazy bound by thinking about what happens when you multiply numbers. – Franz Aug 19 '17 at 1:23

This is just another version of Ross Millikan's answer.

Let $N \equiv 10x+n \pmod{100}$ where n is an odd digit.

\begin{align} (10x + 1)^2 \equiv 10(2x+0)+1 \pmod{100} \\ (10x + 3)^2 \equiv 10(6x+0)+9 \pmod{100} \\ (10x + 5)^2 \equiv 10(0x+2)+5 \pmod{100} \\ (10x + 7)^2 \equiv 10(4x+4)+9 \pmod{100} \\ (10x + 9)^2 \equiv 10(8x+8)+1 \pmod{100} \\ \end{align}

A simple explanation.

1. Squaring means multiplication, multiplication means repeatative additions.

2. Now if you add even no.s for odd no. of times or odd no.s for even no. of times you will always get an even no.

Hence, square of all the even no.s are even, means the last digit is always even.

1. If you add odd no.s for odd no. of times you will always get an odd no.

Coming to the squares of odd no.s whose results are >= 2 digits. Starting from 5^2 = 25, break it as 5+5+5+5+5, we have a group with even no. of 5 and one extra 5. According to my point no. 2 the even group will always give you a even no. i.e. 20, means the last digit is always even. Addition of another 5 with 20 makes it 25, 2 is even.

Taking 7^2, 7+7+7+7+7+7+7, group of six 7's = 42 plus another 7 = 49.

Now consider 9^2, 9+9+9+9+9+9+9+9+9, group of eight 9's = 72 plus another 9 = 81, (72+9 gets a carry of 1 making the 2nd last digit even)

35^2 = group of twenty four 34's (1190) plus 35 = 1225, carry comes.

In short just check the last digit of no. that you can think of in the no. co-ordinate (Real and Imaginary) it will always be b/w 0-9 so the basic principle (point 2 and 3) will never change. Either the last digit will be an even or the 2nd last digit will become even with a carry. So the 1 digit sq can come odd, 1 and 9, as there is no carry. I have kept it as an exception in point 3.

BTW many, including the author may not like my lengthy explanation as mine is not a mathematical one, full of tough formulae. Sorry for that. I'm not from mathematical background and never like maths.

• "35^2 = group of twenty four 34's (1190) plus 35 = 1225, carry comes."? One of the burdens of being a mathematician is to present your arguments and then deal with any criticism that follows. It's got nothing to do with you. Whoever you are, if you publish a turkey, someones going to roast it. – steven gregory Aug 20 '17 at 23:13
• That's a typo. That will be odd+odd = even. I saw that error but didn't edit it. – NewBee Aug 23 '17 at 14:26

Let b be last digit of odd perfect square a,then b can be 1,9 or 5. For b=1,9; $a^2-b$ is divisible by 4, $(a^2-b)/10$ is even. For b=5 ;a always ends in 25.