Happy number

Tree showing all happy numbers up to 100

In number theory, a happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit. For instance, 13 is a happy number because , and . On the other hand, 4 is not a happy number because the sequence starting with and eventually reaches , the number that started the sequence, and so the process continues in an infinite cycle without ever reaching 1. A number which is not happy is called sad or unhappy.

More generally, a -happy number is a natural number in a given number base that eventually reaches 1 when iterated over the perfect digital invariant function for .[1]

The origin of happy numbers is not clear. Happy numbers were brought to the attention of Reg Allenby (a British author and senior lecturer in pure mathematics at Leeds University) by his daughter, who had learned of them at school. However, they "may have originated in Russia" (Guy 2004:§E34).

  1. ^ "Sad Number". Wolfram Research, Inc. Retrieved 16 September 2009.