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 1, 2, 3, …, 2007?
I have started to make a list of all square numbers and adding their digits in an excel file. ... Until now, I have got good numbers as 1, 4, 7, 9, 10, 13, 16, 19. But, this method takes very long. ... Is there a shorter and smarter way to solve this problem.
To be formal about this note that for $r$ large enough and $s$ a single decimal digit $$ (10^r-s)^2 = 10^{2r}-2s \cdot 10^r+r^2 = 9\cdot(10^{2r-1}+10^{2r-2}+\dots 10^{r+3})+(100-2s)\cdot10^r+s^2$$
So we begin with a string of $9$s which is $r-3$ long followed by two digits which are fixed (and may be zero or $9$), then a string of zeros followed by either one or two digits of $s^2$. Every time you increase $r$ by one, the digit sum increases by the addition of a single leading $9$.
Take $s=1$ to see what happens
$9^2=81$
$99^2=9801$
$999^2=998001$
This deals with $9,18, 27\dots$
With $s=2$
$8^2=64$
$98^2=9604$
$998^2=996004$
Which deals with $10,19,28\dots$
With $s=3$
$7^2=49$
$97^2=9409$
$997^2=994009$
Which deals with $13,22,31\dots$
$s=4$ deals with multiples of $9$ again.
$s=5$ gives
$5^2=25$
$95^2=9025$
$995^2=990025$
And this deals with $7,16,25\dots$
With the addition of a few early cases which these miss, you can show that you hit every positive element of every class of quadratic residue modulo $9$