# Is there a perfect square (other than 9) all of whose digits are 7, 8, or 9?

Clearly, $$3^2=9$$ is a perfect square, all of whose digits are $$7$$, $$8$$, or $$9$$. Are there any other perfect squares with this property?

This is an interesting question that does not seem to be solved yet, coming from AoPS (https://artofproblemsolving.com/community/c6h1928519). As duck_master seems to show, it should be impossible to solve this problem by analyzing the quadratic residues modulo $$10^n$$ for some $$n$$.

I strongly suspect the answer is no. I have been running a Python script for quite some time, and it has checked squares up to $$(50,000,000,000)^2$$ with no results (unless I messed up the code).

• As a minimum it has to be a number with the lowest order digit 3 or 7. These squares have the lowest digit 9. There is no way to end in 7 or 8. – herb steinberg Oct 16 '19 at 3:56
• The number to be squared has to be $\equiv\pm17\pmod{50}$ for the two last digits to be a legal combo. I'm sure the folks at AOPS have checked it higher. I suspect $p$-adic techniques to prove that congruences modulo $10^n$ won't settle this. – Jyrki Lahtonen Oct 16 '19 at 4:05
• I would suggest you also add in the example which you've given in the AoPS forum. I had to go there to get a little grasp of what the problem was. – user712576 Oct 16 '19 at 15:32
• Is the choice an arbitrary one? What about $5,6,7$. Can they exhibit the same property as well? – user712576 Oct 16 '19 at 16:30
• And then there are also numbers like $7917^2=62678889$, which really close in but fails at the first digits. Another way of looking at the problem is that a positive integer made up of only $7,8 or 9$ cannot be expressed as the sum of consecutive odd numbers. – user712576 Oct 16 '19 at 17:32

A short proof for the fact that $$\ldots88889$$ will appear as the last decimal digits of a square. Consider the modular inverse of $$3$$ modulo $$10^m$$. That is, let $$n\equiv\ldots 66667$$. Then $$(3n)^2\equiv1\pmod {10^m}$$ and therefore $$n^2$$ is the modular inverse of $$9$$. Modulo $$10^m$$ we have $$-1/9\equiv\ldots11111$$, so we also have $$n^2\equiv(1/3)^2=1/9\equiv-(\ldots11111)\equiv\ldots88889\pmod{10^m}.$$

Of course, this does not settle the main question, only proving the futility of trying to prove the non-existence of such squares by studying any finite segment of least significant digits.

• In other words, check out the last digits of $7^2$, $67^2$, $667^2$, $6667^2$,... – Jyrki Lahtonen Oct 16 '19 at 4:16
• You've proved that $\ldots66667$, when squared, ends in $\ldots88889$. Can you clarify how this may help in the big picture? Are you claiming that if a perfect square has only the digits $7$, $8$, and $9$, then it must necessarily end in $\ldots88889$? – greenturtle3141 Oct 16 '19 at 4:46
• @greenturtle3141 Unfortunately no. The guy on AOPS explained why the three last digits of the square must be $889$. But for example $\ldots7889$ is not ruled out. For example $167^2=27889$. I only wanted to give a "local" argument showing that squares ending with $\ldots88889$ exist for any number of $8$s. This is worthless for the purposes of the main question. – Jyrki Lahtonen Oct 16 '19 at 4:53

COMMENT: We can work on 'construction' of such a number.I propose following method which is based on optimization of digits; consider following experiment. Let the number of digits which are not 7, 8 or 9 be x. Consider 7 digits number $$d_1d_2d_3d_4d_5d_6d_7$$; we start with number $$3161517$$, we have:

$$3161517^2=995189741289$$; x=5

Where $$d_3=6$$, we try 7 for this digit:

$$3171717^2=10059788728089$$; x=6

So $$d_3<7$$ is more desirable; now we work on $$d_4$$ and start with :

$$3162617^2=10002146288689$$; x=7

So $$d_4<2$$; we try $$d_4=0$$:

$$3160617^2=9989499820689$$; x=4

So $$d_4=0$$ is best. Now we work on $$d_5$$:

$$d_5=7$$ gives $$3160717^2=9990131954089$$; x=7

$$d_5=$$ gives $$3160517^2=9988867707289$$; x=3

With $$d_5=4$$; x=5 and with $$d_5=3$$; x=7, so optimum digits for minimum x are:

$$d_1=3, d_2=1, d_3=6, d_4=0, d_5=5, d_6=1, d_7=7$$ and optimized number is $$3160517$$.

For example based on this method I found $$88317^2=7799892489$$ with x=2. Surely we can find numbers with x=1. I think finding a number with x=0 is probable.An efficient computer program can surely help.