How big is $\{n\in\Bbb N\mid 1\leq n\leq 2000\text{ and the digital sum of }n^2=21\}$

combinatoricsrecreational-mathematics

well,the title of the question makes it clear,

The question is :find the number of natural numbers between 1 to 2000 such that the sum of digits of their squares is equal to 21.

my approach:
just to make the question more clear I want to illustrate with help of an example .
$$89^2 = 7921$$and sum of digits of $7921$ is $7+9+2+1=19$
now since the squares of numbers from $1$ to $2000$
can be from $1$ to $7$ digits ,I could not find any way except calculating the squares by hand and adding their digits .so,is there a better method for solving this question? any help is greatly appreciated.

Best Answer

The number is $0$.

Note that the sum of the digits of $n$ is congruent to $n$ mod $9$.

If $n$ is divisible by $3$ then $n^2$ is divisible by $9$, but $21$ is not. If $n$ is not divisible by $3$ then neither is $n^2$, but $21$ is. And we are done.

Related Question