Recognizing squares

Suppose you’re given a number and you’d like to tell whether its a square, or at least you’d like to be able to determine quickly if it’s not a square. This post began as a thread I wrote on Twitter.

For starters, the last digit of a square in base 10 must be 0, 1, 4, 5, 6, or 9. If a number ends in 3, for example, it’s not a square.

Now suppose the last two digits of a square are yz. What does z tell us about y?

  • If z = 1, 4, or 9, then y is even.
  • If z = 6, then y is odd.
  • If z = 0, then y = 0.
  • If z = 5, then y = 2.

Now suppose the last three digits are xyz. What does z tell us about x? Nothing, for most values of z. If z is 1, 4, 6, or 9 then x could be any digit.

If z = 5, then x = 0, 2, or 6.

If z = 0, then our number is a multiple of 100, and dividing by 100 puts us back where we started: z is the last digit of a square, and so it must be 0, 1, 4, 5, 6, or 9.

Hexadecimal

Now let’s switch gears and work in base 16. Something interesting happens right off the bat.

If n is a square, then the last hexadecimal digit of n is a square. That is, the last digit can only be 0, 1, 4, or 9.

Following the pattern above, if the last two hexadecimal digits of a square are yz, what does z tell us about y?

  • If z = 0, then y = 0, 1, 4, or 9.
  • If z = 4, then y is even.
  • If z = 1 or 9, then y could be anything.

Duodecimal

Finally, let’s look at base 12.

As with base 16, if n is a square, then the last duodecimal digit of n is a square, i.e. it can only be 0, 1, 4, or 9.

If the last two duodecimal digits of a square are yz, what does z tell us about y?

  • If z = 0, then y = 0 or 3.
  • If z = 1, then y is even.
  • If z = 4, then y = 0, 1, 4, 5, 8, or 9.
  • If z = 9, then y = 0 or 6.

Related posts