Happy Number Calculator

Positive integer =
 
Result =

A happy number has the following properties: In a given base, the sum of the squares of all the digits of the number is the new number.

Find the sum of the squares of all the digits again, and repeat this process. The final result must be 1.

For example, taking decimal as an example:

2 8 → 2^2+8^2=68 → 6^2+8^2=100 → 1^2+0^2+0^2=1

3 2 → 3^2+2^2=13 → 1^2+3^2=10 → 1^2+0^2=1

3 7 → 3^2+7^2=58 → 5^2+8^2=89 → 8^2+9^2=145 → 1^2+4^2+5^2=42 → 4^2+2^2=20 → 2^2+0^2=4 → 4^2=16 → 1^2+6^2=37……

Therefore, 28 and 32 are happy numbers, and in the calculation process of 37, 37 appears repeatedly. The result of continued calculation will only be a cycle of the above numbers, and 1 will not appear, so 37 is not a happy number.

Numbers that are not happy numbers are called unhappy numbers. The sum of the squares of the digits of all unhappy numbers will eventually enter a cycle of 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4.

In decimal system, the happy numbers within 100 are (sequence A00770 in OEIS): 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100.

Perhaps we can find something more interesting in a base less than 10. This way, there won't be letters in the middle of the number. 167 is 5 more than the multiple of 9, so in a base that can divide 9, the last digit of the number is 5, which looks much more festive than the clumsy 7. (Of course, this is only for our eyes that are used to the decimal system. In the 9th base, 5 means something different than we think.) In the 9th base, 167 is written as 205, but I personally prefer the 81-base 25, which is very concise.

Studying 167 in different bases leads to another interesting fact: 167 is a strictly non-palindrome, meaning it cannot be written as a palindrome (a number that reads the same forward and backward) in any base between 2 and 165. (We stopped at base 165 because it is 167-2, and any number n in base n-1 is a palindrome, and looks like 11.) So far, we don't know the number of strictly non-palindromes, but the next non-palindrome after 167 is 179, and the next is 223.

In addition to the above features, which are sufficient to justify a celebration, 167 is also a safe prime, a very cototient prime, and a fully cyclic prime. I particularly like the last one: it means that there is a 166-digit number whose multiples are cyclic permutations of digits. That is, when you multiply this number by an integer, the product you get is exactly the digits of the original number, in the same order, but with a different starting point, for example, 142857×2=285714.