Report

Help us improve this tool

Happy Number Calculator

Determine if a number is a happy number by repeatedly replacing it with the sum of the squares of its digits. Visualize the happiness journey and find all happy numbers in any range.

O M T

What is a Happy Number?

A happy number is a positive integer that eventually reaches 1 when you repeatedly replace it with the sum of the squares of its digits. For example, 19 is happy because: 1² + 9² = 82, then 8² + 2² = 68, then 6² + 8² = 100, then 1² + 0² + 0² = 1. Numbers that never reach 1 are called unhappy or sad numbers. For more number theory tools, check our Collatz Conjecture Calculator and Fibonacci Numbers Calculator.

How to Use the Happy Number Calculator

  1. Enter a number: Type any positive integer into the input field. Try the quick examples for classic happy and unhappy numbers.
  2. Choose a mode: Use "Check Single Number" to analyze one number in depth, or "Find All Happy Numbers in Range" to discover every happy number from 1 to N.
  3. Analyze results: See the complete digit-squaring sequence, step-by-step breakdown, and whether the number is happy or unhappy.

The Unhappy Cycle

Every unhappy number eventually enters the same 8-number cycle: 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4. This remarkable fact means you only need to check if the sequence ever reaches 4 to determine that a number is unhappy.

Happy Numbers Under 100

There are exactly 20 happy numbers between 1 and 100: 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100.

Interesting Properties of Happy Numbers

  • Digit Permutation Invariance: If a number is happy, any rearrangement of its digits is also happy. For example, since 19 is happy, 91 is also happy.
  • Zero Insertion Invariance: Inserting or removing zeros does not change whether a number is happy.
  • Happy Primes: A happy prime is a number that is both happy and prime. The first few are: 7, 13, 19, 23, 31, 79, 97.
  • Density: The density of happy numbers among all positive integers is approximately 14.3%.

Frequently Asked Questions

What is a happy number?

A happy number is a positive integer that eventually reaches 1 when you repeatedly replace it with the sum of the squares of its digits. For example, 19 is happy because: 1² + 9² = 82 → 68 → 100 → 1.

What happens to unhappy numbers?

Unhappy (or sad) numbers never reach 1. Instead, they eventually enter an infinite cycle: 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4.

What are all the happy numbers under 100?

The happy numbers under 100 are: 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100. That is 20 happy numbers out of 100.

Is there a pattern to happy numbers?

Happy numbers share interesting properties: any permutation of the digits of a happy number is also happy. Additionally, inserting or removing zeros does not change happiness. The density of happy numbers is approximately 14.3% among all positive integers.

Who discovered happy numbers?

Happy numbers were first studied by Reg Allenby in 1966. The concept gained popularity through recreational mathematics. The term "happy number" is attributed to a young student who brought the idea to mathematicians at Cambridge.