Let $a_n $ be the smallest number such that $n$ is the sum of the square of each digit of $a_n$. If $a_k =\overline {13d6}$ with $d $ being a digit, determine $k$.
example: $a_5=12$, $a_6=112$
What I thought:
-See that only $3\le d\le 6$ can works.
-Use the Lagrange's squares to conclude the $d $ that works exactly.
$a_k=13d6$ means that $$k=1^2+3^2+d^2+6^2$$ and thus $$k=46+d^2$$
It is correct to awesome that $3\leq d \leq 6$ holds. If not, then a reordering of the number would be smaller, thus $a_k$ would not be smallest one.
Now, lets test these numbers:
$d=3 \Rightarrow k=55$
Here, with a naive approach of always using the highest possible number and putting it to the end of the number, we reach $a_{55}=1127$, lower than the number in question. Thus $d=3$ is not possible.
$d=4 \Rightarrow k=62$
Here, $a_{62}=237$. Again lower than before.
$d=5 \Rightarrow k=71$
Here, we reach $a_{71} = 11128$, a possible candidate.
$d=6 \Rightarrow k=82$
Here, we reach $a_{82} = 19$, way lower.
So as all other candidates are way lower than $13d6$, $k=71$ holds!