In number theory, a happy number is a number which eventually reaches 1 when the number is replaced by the sum of the square of each digit. For instance, 13 is a happy number because 1 2 + 3 2 = 10 {\displaystyle 1^{2}+3^{2}=10} , and 1 2 + 0 2 = 1 {\displaystyle 1^{2}+0^{2}=1} . On the other hand, 4 is not a happy number because the sequence starting with 4 2 = 16 {\displaystyle 4^{2}=16} and 1 2 + 6 2 = 37 {\displaystyle 1^{2}+6^{2}=37} eventually reaches 2 2 + 0 2 = 4 {\displaystyle 2^{2}+0^{2}=4} , 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 b {\displaystyle b} -happy number is a natural number in a given number base b {\displaystyle b} that eventually reaches 1 when iterated over the perfect digital invariant function for p = 2 {\displaystyle p=2} . The origin of happy numbers is not clear. Happy numbers were brought to the attention of Reginald 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."
Happy numbers and perfect digital invariants
Formally, let n {\displaystyle n} be a natural number. Given the perfect digital invariant function
F p , b ( n ) = ∑ i = 0 ⌊ log b n ⌋ ( n mod b i + 1 − n mod b i b i ) p {\displaystyle F_{p,b}(n)=\sum _{i=0}^{\lfloor \log _{b}{n}\rfloor }{\left({\frac {n{\bmod {b^{i+1}}}-n{\bmod {b^{i}}}}{b^{i}}}\right)}^{p}} . for base b > 1 {\displaystyle b>1} , a number n {\displaystyle n} is b {\displaystyle b} -happy if there exists a j {\displaystyle j} such that F 2 , b j ( n ) = 1 {\displaystyle F_{2,b}^{j}(n)=1} , where F 2 , b j {\displaystyle F_{2,b}^{j}} represents the j {\displaystyle j} -th iteration of F 2 , b {\displaystyle F_{2,b}} , and b {\displaystyle b} -unhappy otherwise. If a number is a nontrivial perfect digital invariant of F 2 , b {\displaystyle F_{2,b}} , then it is b {\displaystyle b} -unhappy.
For example, 19 is 10-happy, as
F 2 , 10 ( 19 ) = 1 2 + 9 2 = 82 {\displaystyle F_{2,10}(19)=1^{2}+9^{2}=82}
F 2 , 10 2 ( 19 ) = F 2 , 10 ( 82 ) = 8 2 + 2 2 = 68 {\displaystyle F_{2,10}^{2}(19)=F_{2,10}(82)=8^{2}+2^{2}=68}
… excerpt ends here. Continue reading the full article.



