# find infinitely many (or all) positive integers n so that n and rev(n) are perfect squares

For a positive integer n, let rev(n) denote the integer obtained by reversing the digits of n. Find infinitely many (or all) positive integers n so that n and rev(n) are perfect squares.

The problem is similar in nature to some contest problem, though I'm not sure if there are neat tricks for solving it.

Call a positive integer n satisfying the problem's condition good. Note that all 3 1-digit perfect squares n satisfy the condition. Also, by inspection, no two digit numbers satisfy the condition. If $$100a+10b+c$$ and $$100c+10b+a$$ are both perfect squares, then $$99(c-a)$$ is the difference of the perfect squares. Note that $$144$$ is good. We can check to see which multiples of 99 from 0 to $$99\cdot 9$$ are the difference of two squares. Alternatively, we can manually check all 3-digit perfect squares to find the good ones. But how can I generalize my approach to numbers with arbitrarily many digits? All perfect squares that are palindromes are obviously good, but how can one find all perfect squares that are palindromes or infinitely many such squares?

• Question/hint: Does $100$ qualify as a number of interest? Jun 5 at 20:57
• Finding all of them seems unreasonable. Should be easy to come up with infinite families, though.
– lulu
Jun 5 at 21:01
• Some related OEIS sequences: A061457 (numbers ending in $0$ allowed), A033294 (extreme digit $0$ not allowed). Jun 6 at 10:22

For a positive integer n, let rev(n) denote the integer obtained by reversing the digits of n. Find infinitely many (or all) positive integers n so that n and rev(n) are perfect squares.

Consider the following construction :

\begin{align}1{\underbrace {0\dots0}_{n \thinspace \text{digits}}2}^2&=1{\underbrace {0\dots0}_{n \thinspace \text{digits}}4{\underbrace {0\dots0}_{n \thinspace \text{digits}}4}}\\\\ 2{\underbrace {0\dots0}_{n \thinspace \text{digits}}1}^2&=4{\underbrace {0\dots0}_{n \thinspace \text{digits}}4\underbrace {0\dots 0}_{n \thinspace \text{digits}}1}\end{align}

All perfect squares that are palindromes are obviously good, but how can one find all perfect squares that are palindromes or infinitely many such squares?

Possible palindromic number family :

\begin{align}1{\underbrace {0\dots0}_{n \thinspace \text{digits}}1{\underbrace {0\dots 0}_{n \thinspace \text{digits}}}1}^2&=1{\underbrace {0\dots 0}_{n \thinspace \text{digits}}2{\underbrace {0\dots 0}_{n \thinspace \text{digits}}3}}{\underbrace {0\dots 0}_{n \thinspace \text{digits}}2{\underbrace {0\dots 0}_{n \thinspace \text{digits}}1 }}\end{align}

• To check ,for the end, why didn't you just go with $10...001^2=10...00200...01$? Jun 6 at 17:03
• When I asked the question, I didn't really think much about palindromes, but I think the general question (finding all n so that n and rev(n) are squares for n <= N) is really hard to solve without a computer. Jun 15 at 2:55
• I think a question that's possible to answer is the following: are there infinitely many non-palindromic squares n whose reverse is also a square? Jun 15 at 2:57

Generalizing a previous answer, the square of any sum of the form $$\sum_{i=0}^{n} A_i 10^i$$ works as long as (1) the $$A_i$$ are all $$0$$, $$1$$, $$2$$, or $$3$$; (2) the nonzero $$A_i$$ are sufficiently far apart and irregularly spaced (*); and (3) there's no pair $$i\neq j$$ such that $$A_i A_j > 5$$. (So if there's a $$3$$, there can only be one; and there can't be both a $$3$$ and a $$2$$.) For instance, $$1001000200002^2=1002001400404044000800004=rev(2000020001001^2).$$ Note here that the squaring operation and the reversing operation commute (i.e., the reversed square of $$x$$ is the square of the reverse of $$x$$). Are there examples where that isn't the case?

(*) More precisely, in the family of solutions described here, the squaring operation doesn't produce carries: there is no $$K$$ such that $$\sum_{i}A_{i}A_{K-i} \ge 10$$.

• I think the "can't produce carries" should be "doesn't produce carries", especially since you're finding a family of solutions rather than classifying all solutions. Jun 6 at 17:08
• @CalvinLin: Yes, that's right. I wasn't sure that there weren't other solutions; and now, based on the other answer, I'm sure that there are. I'll edit it. Jun 7 at 23:03

You ended on the questions how can one find all perfect squares that are palindromes or infinitely many such squares?
and were given two ways to generate the latter, so I'll address the former.

The complete list of numbers up to a specific upper bound is currently only heuristically found.
A Mathematica procedure to obtain all such numbers $$\leq n^2$$ is

Select[Range[0, n]^2, IntegerQ[Sqrt[IntegerReverse[#]]]&]\

A procedure to obtain their square roots $$\leq n$$ is

Select[Range[n], IntegerQ[Sqrt[FromDigits[Reverse[IntegerDigits[ #^2]]]]] &]

Below is the list of all perfect squares $$\leq 1'000'000$$ whose reverse is also a perfect square, with palindromic numbers in $$\color{blue}{blue}$$, non-palindromic in $$\color{red}{red}$$, and multiples of $$10$$ in black, as they yield reverses with leading zeroes.

Notably $$\color{blue}{26^2=676}$$, $$\color{red}{99^2=9801}$$, $$260^2=67600$$, $$\color{blue}{264^2=69696}$$, $$\color{blue}{307^2=94249}$$, $$330^2=108900$$ and $$\color{blue}{836^2=698896}$$ stand out as numbers that are not found with the generalization mentioned in previous answers.

roots perfect squares rev(perfect squares)
A102859 A061457
$$\color{blue}{0}$$ $$\color{blue}{0}$$ $$\color{blue}{0}$$
$$\color{blue}{1}$$ $$\color{blue}{1}$$ $$\color{blue}{1}$$
$$\color{blue}{2}$$ $$\color{blue}{4}$$ $$\color{blue}{4}$$
$$\color{blue}{3}$$ $$\color{blue}{9}$$ $$\color{blue}{9}$$
10 100 001
$$\color{blue}{11}$$ $$\color{blue}{121}$$ $$\color{blue}{121}$$
$$\color{red}{12}$$ $$\color{red}{144}$$ $$\color{red}{441}$$
$$\color{red}{13}$$ $$\color{red}{169}$$ $$\color{red}{961}$$
20 400 004
$$\color{red}{21}$$ $$\color{red}{441}$$ $$\color{red}{144}$$
$$\color{blue}{22}$$ $$\color{blue}{484}$$ $$\color{blue}{484}$$
$$\color{blue}{26}$$ $$\color{blue}{676}$$ $$\color{blue}{676}$$
30 900 009
$$\color{red}{31}$$ $$\color{red}{961}$$ $$\color{red}{169}$$
$$\color{red}{33}$$ $$\color{red}{1089}$$ $$\color{red}{9801}$$
$$\color{red}{99}$$ $$\color{red}{9801}$$ $$\color{red}{1089}$$
100 10000 00001
$$\color{blue}{101}$$ $$\color{blue}{10201}$$ $$\color{blue}{10201}$$
$$\color{red}{102}$$ $$\color{red}{10404}$$ $$\color{red}{40401}$$
$$\color{red}{103}$$ $$\color{red}{10609}$$ $$\color{red}{90601}$$
110 12100 00121
$$\color{blue}{111}$$ $$\color{blue}{12321}$$ $$\color{blue}{12321}$$
$$\color{red}{112}$$ $$\color{red}{12544}$$ $$\color{red}{44521}$$
$$\color{red}{113}$$ $$\color{red}{12769}$$ $$\color{red}{96721}$$
120 14400 00441
$$\color{blue}{121}$$ $$\color{blue}{14641}$$ $$\color{blue}{14641}$$
$$\color{red}{122}$$ $$\color{red}{14884}$$ $$\color{red}{48841}$$
130 16900 00961
200 40000 00004
$$\color{red}{201}$$ $$\color{red}{40401}$$ $$\color{red}{10404}$$
$$\color{blue}{202}$$ $$\color{blue}{40804}$$ $$\color{blue}{40804}$$
210 44100 00144
$$\color{red}{211}$$ $$\color{red}{44521}$$ $$\color{red}{12544}$$
$$\color{blue}{212}$$ $$\color{blue}{44944}$$ $$\color{blue}{44944}$$
220 48400 00484
$$\color{red}{221}$$ $$\color{red}{48841}$$ $$\color{red}{14884}$$
260 67600 00676
$$\color{blue}{264}$$ $$\color{blue}{69696}$$ $$\color{blue}{69696}$$
300 90000 00009
$$\color{red}{301}$$ $$\color{red}{90601}$$ $$\color{red}{10609}$$
$$\color{blue}{307}$$ $$\color{blue}{94249}$$ $$\color{blue}{94249}$$
310 96100 00169
$$\color{red}{311}$$ $$\color{red}{96721}$$ $$\color{red}{12769}$$
330 108900 009801
$$\color{blue}{836}$$ $$\color{blue}{698896}$$ $$\color{blue}{698896}$$
990 980100 001089
1000 1000000 0000001

If n and rev(n) are perfect squares, then 100n is a perfect square, rev(100n) = rev(n) is a square, so 100n is also a solution. On the other hand, if 100n is a perfect square, then so is n, and rev(100n) = rev(n) is als a square. So we can ignore trivial solution ending in an even number of 0’s, and numbers ending in an odd number of 0’s are not square. We only look for n not ending in 0.

For an exhaustive search to find all solutions n <= N for some large fixed N, we iterate through all squares <= N that are not multiples of 10. Now every square ends in 1, 4, 5, 6 or 9, so we can ignore all squares where rev(n) ends in 2, 3, 7 or 8, which is all squared starting with 2, 3, 5, 7 or 8.

We can do the same for the last 2, 3, 4 or 5 digits and reduce the number of squares to be checked massively.