ArticleslgStudy

mathematics

Happy number

Happy number is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Happy number rather than just read about it. In short: In number theory, a happy number is a number which eventually reaches 1 when the number is replaced by the sum of the square of each digit. For instance, 13 is a happy number because 12+32=10, and 12+02=1.

Happy number — main illustration
Happy number — illustration

Key takeaways

  • Happy number belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Happy number to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Happy number from memory before moving on to harder problems.

Reference excerpt

In number theory, a happy number is a number which eventually reaches 1 when the number is replaced by the sum of the square of each digit. For instance, 13 is a happy number because 12+32=10, and 12+02=1. On the other hand, 4 is not a happy number because the sequence starting with 42=16 and 12+62=37 eventually reaches 22+02=4, the number that started the sequence, and so the process continues in an infinite cycle without ever reaching 1. A number which is not happy is called sad or unhappy. More generally, a b-happy number is a natural number in a given number base b that eventually reaches 1 when iterated over the perfect digital invariant function for p=2. The origin of happy numbers is not clear. Happy numbers were brought to the attention of Reginald Allenby (a British author and senior lecturer in pure mathematics at Leeds University) by his daughter, who had learned of them at school. However, they "may have originated in Russia."

Happy numbers and perfect digital invariants

Formally, let n be a natural number. Given the perfect digital invariant function

Fp,b(n)=∑i=0⌊logbn⌋(nmodbi+1−nmodbibi)p. for base b>1, a number n is b-happy if there exists a j such that F2,bj(n)=1, where F2,bj represents the j-th iteration of F2,b, and b-unhappy otherwise. If a number is a nontrivial perfect digital invariant of F2,b, then it is b-unhappy.

For example, 19 is 10-happy, as

F2,10(19)=12+92=82 F2,102(19)=F2,10(82)=82+22=68 F2,103(19)=F2,10(68)=62+82=100 F2,104(19)=F2,10(100)=12+02+02=1

For example, 347 is 6-happy, as

F2,6(347)=F2,6(13356)=12+32+32+52=44 F2,62(347)=F2,6(44)=F2,6(1126)=12+12+22=6 F2,63(347)=F2,6(6)=F2,6(106)=12+02=1

There are infinitely many b-happy numbers, as 1 is a b-happy number, and for every n, bn (10n in base b) is b-happy, since its sum is 1. The happiness of a number is preserved by removing or inserting zeroes at will, since they do not contribute to the cross sum.

Natural density of b-happy numbers By inspection of the first million or so 10-happy numbers, it appears that they have a natural density of around 0.15. The 10-happy numbers do not have an asymptotic density. The upper density of the happy numbers is greater than 0.18577, and the lower density is less than 0.1138.

Happy bases

A happy base is a number base b where every number is b-happy. The only happy integer bases less than 5×108 are base 2 and base 4.

Specific b-happy numbers

4-happy numbers For b=4, the only positive perfect digital invariant for F2,b is the trivial perfect digital invariant 1, and there are no other cycles. Because all numbers are preperiodic points for F2,b, all numbers lead to 1 and are happy. As a result, base 4 is a happy base.

6-happy numbers For b=6, the only positive perfect digital invariant for F2,b is the trivial perfect digital invariant 1, and the only cycle is the eight-number cycle

5 → 41 → 25 → 45 → 105 → 42 → 32 → 21 → 5 → ... and because all numbers are preperiodic points for F2,b, all numbers either lead to 1 and are happy, or lead to the cycle and are unhappy. Because base 6 has no other perfect digital invariants except for 1, no positive integer other than 1 is the sum of the squares of its own digits. In base 10, the 74 6-happy numbers up to 1296 = 64 are (written in base 10):

1, 6, 36, 44, 49, 79, 100, 160, 170, 216, 224, 229, 254, 264, 275, 285, 289, 294, 335, 347, 355, 357, 388, 405, 415, 417, 439, 460, 469, 474, 533, 538, 580, 593, 600, 608, 628, 638, 647, 695, 707, 715, 717, 767, 777, 787, 835, 837, 847, 880, 890, 928, 940, 953, 960, 968, 1010, 1018, 1020, 1033, 1058, 1125, 1135, 1137, 1168, 1178, 1187, 1195, 1197, 1207, 1238, 1277, 1292, 1295

10-happy numbers For b=10, the only positive perfect digital invariant for F2,b is the trivial perfect digital invariant 1, and the only cycle is the eight-number cycle

4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4 → ... and because all numbers are preperiodic points for F2,b, all numbers either lead to 1 and are happy, or lead to the cycle and are unhappy. Because base 10 has no other perfect digital invariants except for 1, no positive integer other than 1 is the sum of the squares of its own digits. In base 10, the 143 10-happy numbers up to 1000 are:

1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193, 203, 208, 219, 226, 230, 236, 239, 262, 263, 280, 291, 293, 301, 302, 310, 313, 319, 320, 326, 329, 331, 338, 356, 362, 365, 367, 368, 376, 379, 383, 386, 391, 392, 397, 404, 409, 440, 446, 464, 469, 478, 487, 490, 496, 536, 556, 563, 565, 566, 608, 617, 622, 623, 632, 635, 637, 638, 644, 649, 653, 655, 656, 665, 671, 673, 680, 683, 694, 700, 709, 716, 736, 739, 748, 761, 763, 784, 790, 793, 802, 806, 818, 820, 833, 836, 847, 860, 863, 874, 881, 888, 899, 901, 904, 907, 910, 912, 913, 921, 923, 931, 932, 937, 940, 946, 964, 970, 973, 989, 998, 1000 (sequence A007770 in the OEIS). The distinct combinations of digits that form 10-happy numbers below 1000 are (the rest are just rearrangements and/or insertions of zero digits):

1, 7, 13, 19, 23, 28, 44, 49, 68, 79, 129, 133, 139, 167, 188, 226, 236, 239, 338, 356, 367, 368, 379, 446, 469, 478, 556, 566, 888, 899. (sequence A124095 in the OEIS). The first pair of consecutive 10-happy numbers is 31 and 32. The first set of three consecutive is 1880, 1881, and 1882. It has been proven that there exist sequences of consecutive happy numbers of any natural number length. The beginning of the first run of at least n consecutive 10-happy numbers for n = 1, 2, 3, ... is

1, 31, 1880, 7839, 44488, 7899999999999959999999996, 7899999999999959999999996, ... As Robert Styer puts it in his paper calculating this series: "Amazingly, the same value of N that begins the least sequence of six consecutive happy numbers also begins the least sequence of seven consecutive happy numbers." The number of 10-happy numbers up to 10n for 1 ≤ n ≤ 20 is

3, 20, 143, 1442, 14377, 143071, 1418854, 14255667, 145674808, 1492609148, 15091199357, 149121303586, 1443278000870, 13770853279685, 130660965862333, 1245219117260664, 12024696404768025, 118226055080025491, 1183229962059381238, 12005034444292997294.

… excerpt ends here. Continue reading the full article.

Illustrations

Happy number: Tree showing all happy numbers until 100, and 130
Tree showing all happy numbers until 100, and 130
Happy number: Sad numbers up to 100 showing the repeating cycle of 8 numbers
Sad numbers up to 100 showing the repeating cycle of 8 numbers

Worked examples

Example 1 — a first encounter with Happy number

Start with the simplest possible case. Write down what Happy number claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Happy number before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Happy number ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Happy number

In research
Happy number appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Happy number in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Happy number is common in secondary-school and first-year university syllabi. It links to neighbouring topics Arithmetic dynamics, Base-dependent integer sequences, so understanding it makes those chapters shorter.
In everyday life
Look for Happy number outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Happy number” →

How to study Happy number in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Happy number means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Happy number out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Happy number in simple terms?

In number theory, a happy number is a number which eventually reaches 1 when the number is replaced by the sum of the square of each digit. For instance, 13 is a happy number because 12+32=10, and 12+02=1.

Why does Happy number matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Happy number?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Happy number.

Tags

  • Arithmetic dynamics
  • Base-dependent integer sequences

Keep exploring