Happy Numbers

© Walter Schneider 2000
(last updated 27/12/2002)


 

Iterate the process of summing up the squares of the digits of a number. If the process terminates in 1 then the original number is called a happy number. Otherwise the number is called unhappy. Examples:

7 -> 49 -> 97 -> 130 -> 10 -> 1, therefore 7 is a happy number.
4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4,therefore 4 is a unhappy number.

Because the sum of the squares of the digits of a number is less than the number for all numbers ≥ 1000 it can be easily proven that all unhappy numbers reach the above listed cycle starting with 4. The first happy numbers are (Sloane's A007770):

1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, ...

The first happy primes are (Sloane's A035497):

7, 13, 19, 23, 31, 79, 97, 103, ...

Not much is known about the distribution of happy numbers. Some questions not yet answered are:

(1) What is the density of the happy numbers? It seems that about 1/7 of all numbers are happy.
(2) Are there arbitrarily long sequences of consecutive happy numbers?
(3) How large can the gaps be?
(4) What about other bases or higher powers?

Here are the results of a computer search up to 1010:

Computer Search of Happy Numbers
up to 1010
Range No. absolut No. percent Largest Block
Length (Start)
Largest Gap
Length (Start)
≤ 10 1 3 0.300 1 (1) 5 (2)
≤ 10 2 20 0.200 2 (31) 18 (50)
≤ 10 3 143 0.143 2 (31) 41 (567)
≤ 10 4 1,442 0.144 4 (7,839) 52 (5,365)
≤ 10 5 14,377 0.144 5 (44,488) 52 (5,365)
≤ 10 6 143,071 0.143 5 (44,488) 72 (488,445)
≤ 10 7 1,418,854 0.142 5 (44,488) 73 (4,488,045)
≤ 10 8 14,255,667 0.143 5 (44,488) 88 (88,889,734)
≤ 10 9 145,674,808 0.146 5 (44,488) 104 (569,199,934)
≤ 1010 1,492,609,148 0.149 5 (44,488) 115 (5,888,999,663)

A list of all happy numbers up to 10,000 is available here.

 

Generalizations

The concept of happy numbers can easily be generalized by considering arbitrary bases and powers instead of squares. Let b ≥ 2 be the base, e ≥ 2 be the exponent and define the value Se,b(a) for each integer a as the sum of the e-th powers of the base-b digits of a. Then we are interested in the fixed points and cycles generated if this function is iterated. The integer a is called happy to base b and power e if the iterated sequence started with Se,b(a) reaches 1.

It's easy to see that for base 2 each positive integer is happy to base 2 and each power e. For other cases a computer search has to be done. In the following tables all fixed points and cycles are listed for bases 2-10 and powers 2 and 3 (Grundman and Teeple).

Fixed points and cycles of S2,b
Base Fixed Points Cycles
2 1  
3 1, 12, 22 2 -> 11 -> 2
4 1  
5 1, 23, 33 4 -> 31 -> 20 -> 4
6 1 32 -> 21 -> 5 -> 41 -> 25 -> 45 -> 105 -> 42 -> 32
7 1, 13, 34, 44, 63 2 -> 4 -> 22 -> 11 -> 2
16 -> 52 -> 41 -> 23 -> 16
8 1, 24, 64 4 -> 20 -> 4
5 -> 31 -> 12 -> 5
15 -> 32 -> 15
9 1, 45, 55 58 -> 108 -> 72 -> 58
82 -> 75 -> 82
10 1 4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4

 

Fixed points and cycles of S3,b
Base Fixed Points Cycles
2 1  
3 1, 122 2 -> 22 -> 121 -> 101 -> 2
4 1, 20, 21, 130, 131, 203, 223, 313, 332  
5 1, 103, 433 14 -> 230 -> 120 -> 14
6 1, 243, 514, 1055 13 -> 44 -> 332 -> 142 -> 201 -> 13
7 1, 12, 22, 250, 251, 305, 505 2 -> 11 -> 2
13 -> 40 -> 121 -> 13
23 -> 50 -> 236 -> 506 -> 665 -> 1424 -> 254 -> 401 -> 122 -> 23
51 -> 240 -> 132 -> 51
160 -> 430 -> 160
161 -> 431 -> 161
466 -> 1306 -> 466
516 -> 666 -> 1614 -> 552 -> 516
8 1, 134, 205, 463, 660, 661 662 -> 670 -> 1057 -> 725 -> 734 -> 662
9 1, 30, 31, 150, 151, 570, 571, 1388 38 -> 658 -> 1147 -> 504 -> 230 -> 38
152 -> 158 -> 778 -> 1571 -> 572 -> 578 -> 1308 -> 660 -> 530 -> 178 -> 1151 -> 152
638 -> 1028 -> 638
818 -> 1358 -> 818
10 1, 153, 370, 371, 407 55 -> 250 -> 133 -> 55
136 -> 244 -> 136
160 -> 217 -> 352 -> 160
919 -> 1459 -> 919

 

References

Dudeney, H.E.: 536 Puzzles & Curious Problems,
New York: Scribner, 1967, Problem 143, pp. 43 and 258-259.
Grundman, H.G. and Teeple, E.A.: Generalized Happy Numbers,
Fibonacci Quarterly, Nov. 2001, Vol. 39, Part 5, pp. 462-466.
Guy, R.K.: Unsolved Problems in Number Theory,
New York: Springer Verlag, 2nd ed. 1994, §E34 Happy numbers, pp. 234-235.
Rivera, C.: Problems & Puzzles: Puzzles, Puzzle 21.- Happy primes,
http://www.primepuzzles.net/puzzles/puzz_021.htm.
Weisstein, Eric W.: Happy Number,
CRC Concise Encyclopedia of Mathematics, Chapman & Hall/CRC 1999.
 
Back to the Homepage of MATHEWS: the Archive of Recreational Mathematics