3

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.

Asaf Karagila
  • 393,674

2 Answers2

9

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.

lulu
  • 70,402
3

This is not an answer, but too long for a comment.

I wrote some Mathematica code that you can use to find how many numbers fit your requirement for some value of $\text{k}$:

k =;
\[Alpha] =;
\[Beta] =;
DigitSum[n_, b_: 10] := Total[IntegerDigits[n, b]];
Length[ParallelTable[
  If[TrueQ[DigitSum[n^2, 10] == k], n, 
   Nothing], {n, \[Alpha], \[Beta]}]]

So, in your case we have $\alpha=1$, $\beta=2000$, and $\text{k}=21$:

In[1]:=k = 21;
\[Alpha] = 1;
\[Beta] = 2000;
DigitSum[n_, b_: 10] := Total[IntegerDigits[n, b]];
Length[ParallelTable[
  If[TrueQ[DigitSum[n^2, 10] == k], n, 
   Nothing], {n, \[Alpha], \[Beta]}]]

Out[1]=0

But when we ask the same question but with $\alpha=0$, $\beta=10^6$, and $\text{k}=10$, we get:

In[2]:=k = 10;
\[Alpha] = 0;
\[Beta] = 10^6;
DigitSum[n_, b_: 10] := Total[IntegerDigits[n, b]];
Length[ParallelTable[
  If[TrueQ[DigitSum[n^2, 10] == k], n, 
   Nothing], {n, \[Alpha], \[Beta]}]]

Out[2]=83
Jan Eerland
  • 28,671