March 19, 2021
A few weeks ago, Scott Matlick reached out to me with observations about the relative likelihood that a positive integer with a given number of digits would be a perfect square. And that got us both wondering. For some perfect squares, when you remove the last digit, you get another perfect square. For example, when you remove the last digit from 256 (\(16^2\)), you get 25 (\(5^2\)).
The first few squares for which this happens are 16, 49, 169, 256 and 361. What are the next three squares for which you can remove the last digit and get a different perfect square? How many more can you find? (Bonus points for not looking this up online or writing code to solve it for you! There are interesting ways to do this by hand, I swear.)
Extra credit: Did you look up the sequence and spoil the puzzle for yourself? Good news, there’s more! In the list above, 169 (\(13^2\)) is a little different from the other numbers. Not only when you remove the last digit do you get a perfect square, 16 (\(4^2\)), but when you remove the last two digits, you again get a perfect square: 1 (\(1^2\)). Can you find another square with both of these properties?
Answer: 1444, 3249, 18496
Explanation:
We let the larger of the two squares be \(b^2\), i.e. the terms in our sequence, and the square obtained by removing the ones digit of \(b^2\) be denoted as \(a^2\). Of course, both \(a\) and \(b\) must be positive integers. Furthermore, let \(0 \leq y \leq 9\) represent the possible value of the ones digit of \(b^2\), such that if we remove it, we get \(a^2\). Mathematically, this can be written as: \(10a^2 + y = b^2\).
Below is a table of the values of \(a\), \(b\), and \(y\) for the given terms of the doubly-perfect sequence:
\(b^2\) | 16 | 49 | 169 | 256 | 361 |
a | 1 | 2 | 4 | 5 | 6 |
b | 4 | 7 | 13 | 16 | 19 |
y | 6 | 9 | 9 | 6 | 1 |
Now, we are interested in constructing a value of \(b\) such that \(b^2\) will be doubly-perfect. In order to do so, we re-arrange our equation for \(b^2\) and get the following inequality:
\begin{equation} \sqrt{10}a \leq b \leq \sqrt{10a^2 + 9} \end{equation}
Since \(\sqrt{10}\) is not an integer, this shows that \(y\) cannot be zero.
When can \(b^2\) be doubly-perfect? Well, according to the above inequality, when there is an integer between \(\sqrt{10}a\) and \(\sqrt{10a^2 + 9}\). This is because \(b\) must be an integer. For example, when \(a = 1\), we have \(\sqrt{10}a \approx 3.16\) and \(\sqrt{10a^2 + 9}\ \approx 4.35\), and so there is the integer 4 in between the two values, and hence we get \(b = 4\) and \(b^2 = 16\), as expected for the first term in the sequence with \(a = 1\). Since 9 is a constant, as \(a\) gets bigger, the bounds on \(b\) will get smaller and smaller and hence we will ever have at most one integer between the two values. It is at those "integer" moments for particular values of \(a\) that will we get the \(b^2\) in our doubly-perfect sequence.
We can capture those "integer" moments using the "floor" function. The "floor" function is defined as the greatest integer less or equal to the argument. For positive arguments, the "floor" function essentially truncates the decimal. This means that for an "integer" moment to occur, we must have:
\begin{equation} \lfloor\sqrt{10a^2 + 9}\rfloor - \lfloor\sqrt{10}a\rfloor = 1 \end{equation}
The solutions to the above equation yields the \(a\) which in turn yields all solutions for \(b^2 = 10a^2 + y\) for some integer \(y\) between 1 and 9 inclusive.
Below is a graph of all of the integer moments for \(a\) going from 1 to 100, as using the above equation:
From the above graph it can be seen that the next four integer moments occur at \(a = 12, 18, 43, 80\). It is expected that those moments become sparser and sparser as \(a\) increases, as the difference between \(\sqrt{10}a\) and \(\sqrt{10a^2 + 9}\) shrinks.
We can therefore expand our doubly-perfect sequence table as follows:
\(b^2\) | 16 | 49 | 169 | 256 | 361 | 1444 | 3249 | 18496 | 64009 |
a | 1 | 2 | 4 | 5 | 6 | 12 | 18 | 43 | 80 |
b | 4 | 7 | 13 | 16 | 19 | 38 | 57 | 136 | 253 |
y | 6 | 9 | 9 | 6 | 1 | 4 | 9 | 6 | 9 |