
3. For any natural number $n$, expressed in base 10, let $S(n)$ denote the sum of all digits of $n$. Find all natural numbers $n$ such that $n=2 S(n)^{2}$.


Solution: We use the fact that 9 divides $n-S(n)$ for every natural number $n$. Hence $S(n)(2 S(n)-1)$ is divisible by 9 . Since $S(n)$ and $2 S(n)-1$ are relatively prime, it follows that 9 divides either $S(n)$ or $2 S(n)-1$, but not both. We also observe that the number of digits of $n$ cannot exceed 4 . If $n$ has $k$ digits, then $n \geq 10^{k-1}$ and $2 S(n)^{2} \leq 2 \times(9 k)^{2}=162 k^{2}$. If $k \geq 6$, we see that

$$
2 S(n)^{2} \leq 162 k^{2}<5^{4} k^{2}<10^{k-1} \leq n
$$

If $k=5$, we have

$$
2 S(n)^{2} \leq 162 \times 25=4150<10^{4} \leq n
$$

Therefore $n \leq 4$ and $S(n) \leq 36$.

If $9 \mid S(n)$, then $S(n)=9,18,27,36$. We see that $2 S(n)^{2}$ is respectively equal to $162,648,1458$, 2592. Only 162 and 648 satisfy $n=2 S(n)^{2}$.

If $9 \mid(2 S(n)-1)$, then $2 S(n)=9 k+1$. Only $k=1,3,5,7$ give integer values for $S(n)$. In these cases $2 S(n)^{2}=50,392,1058,2048$. Here again 50 and 392 give $n=2 S(n)^{2}$.

Thus the only natural numbers wth the property $n=2 S(n)^{2}$ are $50,162,392,648$.
