Счастливые числа

Numbers that reach 1 through iterated digit-square sums: where math meets joy

A happy number is defined by a simple process: take any positive integer, replace it with the sum of the squares of its digits, and repeat. If this process eventually reaches 1, the number is happy. If it loops endlessly without ever reaching 1, the number is unhappy. This deceptively simple concept leads to rich mathematical structures and connections to prime numbers.

Как работает алгоритм счастья?

The process is straightforward: take each digit of the number, square it, and add all the squares together. Then repeat with the result. Every number either reaches 1 (happy) or enters the cycle 4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4 (unhappy).

Example: Is 23 happy?

232² + 3² = 4 + 9 = 13
131² + 3² = 1 + 9 = 10
101² + 0² = 1 + 0 = 1

¡23 is a happy number!

Example: Is 4 happy?

44² = 16
161² + 6² = 1 + 36 = 37
373² + 7² = 9 + 49 = 58
585² + 8² = 25 + 64 = 89
898² + 9² = 64 + 81 = 145
1451² + 4² + 5² = 1 + 16 + 25 = 42
424² + 2² = 16 + 4 = 20
202² + 0² = 4 + 0 = 4

¡4 is an unhappy number -- it enters an infinite loop!

Свойства счастливых чисел

  • The first few happy numbers are: 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100...
  • Approximately 14.3% of all positive integers are happy numbers.
  • Every unhappy number eventually enters the same 8-number cycle: 4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20.
  • If a number is happy, then every number in its iteration sequence is also happy.

Счастливые простые числа

A happy prime is a number that is both happy and prime. These doubly special numbers combine two independent mathematical properties. They were featured in a 2007 episode of Doctor Who, bringing recreational mathematics to mainstream television.

Happy primes up to 200:

Счастливые числа в культуре

Happy numbers gained popular attention when they appeared in the Doctor Who episode "42" (2007), where the crew of a spaceship had to identify happy primes to unlock security doors. The concept was introduced mathematically by Reg Allenby in 1966 and has since become a popular topic in recreational mathematics and programming challenges.

Happy Numbers up to 500

There are 76 happy numbers between 1 and 500. Click on any to see its full analysis.

Вы знали

Preguntas Frecuentes

How do you determine if a number is happy?

Apply the digit-squaring algorithm: take any positive integer, replace it with the sum of squares of its digits, and repeat. Track results in a set. If reaching 1, the number is happy. If encountering a previously seen value (detecting a cycle), the number is unhappy. For example, 23: 2²+3²=13; 1²+3²=10; 1²+0²=1 (happy). For 2: 2²=4; 4²=16; 1²+6²=37; 3²+7²=58; 5²+8²=89; 8²+9²=145; 1²+4²+5²=42; 4²+2²=20; 2²+0²=4 (cycle detected at 4, unhappy). Most implementations use a set to track seen values, enabling cycle detection upon re-encountering. Programming requires iteration handling, digit extraction, and summation. Manual calculation becomes tedious for large numbers with many iterations.

Why are there exactly 20 happy numbers from 1 to 143?

This represents empirical observation of happy number distribution rather than following obvious pattern. The specific count (20/143 ≈ 14%) matches the long-term frequency (approximately 1 in 7 numbers). The relatively uniform distribution across different ranges suggests happy numbers distribute independently of digit patterns. Different ranges contain varying happy number patterns; some ranges might have 13 in 130 numbers, others 21 in 150 numbers—but averaging across large ranges yields consistent ~14.3% proportion. No closed formula predicts how many happy numbers exist up to n; the count requires iterative checking. The stability of this proportion across ranges, despite lacking simple explanation, demonstrates deep mathematical structure. Research continues investigating why this proportion stabilizes so predictably.

What exactly is the cycle that unhappy numbers reach?

The unhappy cycle in base 10 is [4, 16, 37, 58, 89, 145, 42, 20], of length 8. Starting from any unhappy number, repeated digit-squaring and summation eventually produces one of these values, after which the sequence cycles through these eight numbers repeatedly. For example, 2→4→16→37→58→89→145→42→20→4→16→... Every unhappy number is guaranteed to reach this cycle regardless of starting value. No other cycles exist in base 10 (proven through exhaustive analysis). The uniqueness of this cycle means all unhappy numbers share identical ultimate behavior—cyclical repetition through the same eight-element sequence. This structure contrasts with happy numbers reaching 1 directly. The deterministic behavior of sad numbers makes them mathematically interesting—despite varied paths, all converge to identical behavior.

Изучите больше числовых концепций