A relative of mine found an algorithm on TikTok that could supposedly calculate the square of any two digit number. The number 35 was used as an example, so I shall use it to explain how it works:
- Multiply the first digit by its successor, in this case we have $3 \cdot 4 =12$.
- Multiply the second digit by itself, so we have $5 \cdot 5 = 25$.
- Append the second product to the end of the first, that is, if we have 12 as the first product and 25 as the second, the result is 1225.
And the number that comes out of 3. is supposed to be the square of that number. It does indeed work for 35 but not for all two digit numbers, like 89: using the algorithm you get 7281, but the square of 89 is 7921. So this begs the question, for what numbers does this algorithm actually give the square of the number? I tried solving it algebraically, taking some two digit number $(xy)_{10}$ with $1 \leq x \leq 9$ and $0 \leq y \leq 9$ and: $$p_1=x(x+1)$$ $$p_2=y²$$ But I don't know how to apply the step 3. algebraically so I could equal it to $(xy) _{10}^2 $. Is there a way to compute this without brute forcing all two digit numbers?
Let our two-digit number be $$n = 10t + u,$$ where $t$ is the tens digit and $u$ is the units digit, $t \in \{1, \ldots, 9\}$, $u \in \{0, \ldots, 9\}$. Then $$n^2 = (10t + u)^2 = 100t^2 + 20tu + u^2.$$ By the algorithm, the first step computes $t(t+1)$. The second step computes $u^2$. The third step computes $$100t(t+1) + u^2 = 100t^2 + 100t + u^2,$$ where I have assumed that if $u^2 < 10$, we prepend a $0$; e.g., $u = 3$ gives us $09$ instead of just $9$. Then we see that the difference between the algorithm and the actual square is $$100t - 20tu = 20t(5 - u).$$ Therefore, in order for the algorithm to work, this difference must be $0$, from which it follows that either $t = 0$ or $u = 5$. Since $n$ is a two-digit number, we cannot have $t = 0$; hence $u = 5$ is the required condition, meaning that the only two-digit numbers for which the algorithm works are $15, 25, 35, 45, 55, 65, 75, 85, 95$.