happy number calculator

positive integer =
 
result =

a happy number has the following characteristics: under a given carry system, the sum of the squares of all 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, take decimal:

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 during 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 squares 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.

maybe we can find something more interesting in bases less than 10. this way there will be no letters between the numbers. 167 is 5 greater than a multiple of 9, so in a base system that can be divided evenly by 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 decimal system. the meaning of 5 in base 9 is different from what we think.) in base 9, 167 is written as 205, but i personally prefer 81 25 in base, it's very concise.

studying 167 in different base systems leads to another interesting fact: 167 is a strictly non-palindrome number, which means that it cannot be written as a palindrome in any base system between 2 and 165. numbers (read the exact same numbers forward and backwards). (the reason we stopped at base 165 is that it is 167-2, and any number n under base n-1 is a palindrome number, which looks like 11.) so far, we have i don’t know the number of strictly non-palindromic numbers, but the next non-palindromic number to 167 is 179, and the next one is 223.

the characteristics listed above are enough to prove the necessity of holding a celebration. in addition, 167 is also a safe prime number, a very cototient prime number, and a fully cyclic prime number. i particularly like the last one: it means there exists a 166-bit number, and each multiple of it is a cyclic permutation of the numbers. that is to say, when you multiply this number by an integer, the product obtained is exactly the number of the original number. the order is the same, but the starting point is different, for example, 142857×2=285714.