Will iterating the sum of the squares of the digits of any number ultimately give $1$?

92 Views Asked by At

I was doing a program where I had to figure out whether the sum of square of digits of a number will ultimately give $1$. For eg: $$68 \;\to\; 6^2+8^2=36+64=100 \;\to\; 1^2+0^2+0^2=1$$

So I wanted to know if this loop gives a single digit number ultimately for every number.

1

There are 1 best solutions below

0
On

Let S(x) be the sum of the squares of the digits of x. You first find T = largest number x so that S(x) >= x. Obviously starting with an x > T will end up with an integer <= T. You can show that T = 99. So you examine all numbers up to 99 and check which cycle they end in.