1

A positive integer $n$ is said to be good if there exists a perfect square whose sum of digits in base $10$ is equal to $n$. For instance, $13$ is good because $7^2=49$ and $4+9=13$. How many good numbers are among the list $\{1, 2, 3, \dotsc, 2007\}$?

I input all the numbers from $1$ to $2007$ into an Excel spreadsheet, squared all the numbers, split the squares into individual digits, added the digits and checked-off on the numbers which are repeating in the original list of numbers from $1$ to $2007$, and the sum of digits of the squares.

But this method takes too long. Is there a smarter way to answer this question?

Mike Pierce
  • 19,406
Math Tise
  • 717
  • 1
  • 5
  • 11

1 Answers1

0

Remember the trick about casting out nines. Summing the digits of a number maintains the remainder on division by $9$. If we work $\bmod 9$ the only squares are $0,1,4,7$, so any number that is not equivalent to one of these will not have a square with that digit sum.

The next part is to show that any number of this form has a square with that digit sum. The sum of digits function is like a logarithm. It is at most $9$ times the number of digits of the original number. To get a digit sum of $2017$ you need a number with hundreds of digits, so I am sure you didn’t get close.

You can find patterns of numbers to handle whole classes of desired sums. If you square $10^k-1$, which is a number with $k\ 9's$ you get $10^{2k}-2\cdot 10^k+1,$ which has $k-1\ 9's,$ an $8,\ k-1 0$'s and a $1$ for a sum of $9k$. That covers all the multiples of $9$.

Ross Millikan
  • 383,099
  • $7$ is also a square mod $9$. – Robert Israel May 29 '18 at 05:01
  • @RobertIsrael: right you are. I stopped too soon because $3^2\equiv 0$ – Ross Millikan May 29 '18 at 05:06
  • @RossMillikan: Please explain the trick about casting out nines. – Math Tise May 29 '18 at 05:45
  • @RossMillikan: I still don't understand the solution, unfortunately. :-S Please can you give an example? – Math Tise May 29 '18 at 05:47
  • For example, $5$ is not a square mod $9$, i.e. there is no integer $x$ such that the remainder on division of $x^2$ by $9$ is $5$, so neither $5$ nor anything of the form $5 + 9 n$ can't the the digit sum of a square. On the other hand, $121 = 4 + 9 \cdot 13$ and $4$ is a square mod $9$, so there could be some integer whose square has sum of digits $121$. – Robert Israel May 29 '18 at 06:07
  • You could see Wikipedia on modular arithmetic. It is a ring like the integers so you can add, subtract, and multiply. When the modulus is not prime, as here, you can have $ab=0$ even though neither $a$ nor $b$ is zero. – Ross Millikan May 29 '18 at 13:51