Happy Number Calculator

Positive integer =
 
Result =

A happy number has the following characteristics: in a given radix, the sum of the squares of all the digits of the number, the new number

is calculated again, and the sum of the squares of all the digits is repeated, and the final result must be 1.

For example, take 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 the cycle of the above numbers, and 1 will not appear. Therefore, 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 the cycle of 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4.

In decimal, 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 will be no letters in the middle of the number. 167 is 5 more than the multiple of 9, so in the 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 accustomed to the decimal system. In the base 9 system, 5 means something different than we imagine.) In the base 9 system, 167 is written as 205, but I personally prefer 25 in the base 81 system, which is very concise.

Studying 167 in different bases leads to another interesting fact: 167 is a strict non-palindrome number, which means that it cannot be written as a palindrome (a number that reads exactly 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.

The features listed above are enough to prove the necessity of holding a celebration. In addition, 167 is a safe prime, a very cototient prime, and a fully cyclic prime. I especially like the last one: it means that there is a 166-digit number whose every multiple is a cyclic permutation of the numbers. That is, when you multiply this number by an integer, the product you get is exactly the digits of the original number, arranged in the same order, but with a different starting point, for example 142857×2=285714.