Happy number

Last updated

In number theory, a happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit. For instance, 13 is a happy number because , and . On the other hand, 4 is not a happy number because the sequence starting with and eventually reaches , 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.

Contents

More generally, a -happy number is a natural number in a given number base that eventually reaches 1 when iterated over the perfect digital invariant function for . [1]

The origin of happy numbers is not clear. Happy numbers were brought to the attention of Reg 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" ( Guy 2004 :§E34).

Happy numbers and perfect digital invariants

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

.

for base , a number is -happy if there exists a such that , where represents the -th iteration of , and -unhappy otherwise. If a number is a nontrivial perfect digital invariant of , then it is -unhappy.

For example, 19 is 10-happy, as

For example, 347 is 6-happy, as

There are infinitely many -happy numbers, as 1 is a -happy number, and for every , ( in base ) is -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. Perhaps surprisingly, then, 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. [2]

Happy bases

Unsolved problem in mathematics:

Are base 2 and base 4 the only bases that are happy?

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

Specific b-happy numbers

4-happy numbers

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

6-happy numbers

For , the only positive perfect digital invariant for 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 , 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 , the only positive perfect digital invariant for 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 , 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. [4] The first set of three consecutive is 1880, 1881, and 1882. [5] It has been proven that there exist sequences of consecutive happy numbers of any natural number length. [6] The beginning of the first run of at least n consecutive 10-happy numbers for n =1, 2, 3, ... is [7]

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." [8]

The number of 10-happy numbers up to 10n for 1  n  20 is [9]

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

Happy primes

A -happy prime is a number that is both -happy and prime. Unlike happy numbers, rearranging the digits of a -happy prime will not necessarily create another happy prime. For instance, while 19 is a 10-happy prime, 91 = 13 × 7 is not prime (but is still 10-happy).

All prime numbers are 2-happy and 4-happy primes, as base 2 and base 4 are happy bases.

6-happy primes

In base 6, the 6-happy primes below 1296 = 64 are

211, 1021, 1335, 2011, 2425, 2555, 3351, 4225, 4441, 5255, 5525

10-happy primes

In base 10, the 10-happy primes below 500 are

7, 13, 19, 23, 31, 79, 97, 103, 109, 139, 167, 193, 239, 263, 293, 313, 331, 367, 379, 383, 397, 409, 487 (sequence A035497 in the OEIS ).

The palindromic prime 10150006 + 7426247×1075000 + 1 is a 10-happy prime with 150007 digits because the many 0s do not contribute to the sum of squared digits, and 12 + 72 + 42 + 22 + 62 + 22 + 42 + 72 + 12 = 176, which is a 10-happy number. Paul Jobling discovered the prime in 2005. [10]

As of 2010, the largest known 10-happy prime is 242643801  1 (a Mersenne prime).[ dubious ] Its decimal expansion has 12837064 digits. [11]

12-happy primes

In base 12, there are no 12-happy primes less than 10000, the first 12-happy primes are (the letters X and E represent the decimal numbers 10 and 11 respectively)

11031, 1233E, 13011, 1332E, 16377, 17367, 17637, 22E8E, 2331E, 233E1, 23955, 25935, 25X8E, 28X5E, 28XE5, 2X8E5, 2E82E, 2E8X5, 31011, 31101, 3123E, 3132E, 31677, 33E21, 35295, 35567, 35765, 35925, 36557, 37167, 37671, 39525, 4878E, 4X7X7, 53567, 55367, 55637, 56357, 57635, 58XX5, 5X82E, 5XX85, 606EE, 63575, 63771, 66E0E, 67317, 67371, 67535, 6E60E, 71367, 71637, 73167, 76137, 7XX47, 82XE5, 82EX5, 8487E, 848E7, 84E87, 8874E, 8X1X7, 8X25E, 8X2E5, 8X5X5, 8XX17, 8XX71, 8E2X5, 8E847, 92355, 93255, 93525, 95235, X1X87, X258E, X285E, X2E85, X85X5, X8X17, XX477, XX585, E228E, E606E, E822E, EX825, ...

Programming example

The examples below implement the perfect digital invariant function for and a default base described in the definition of happy given at the top of this article, repeatedly; after each time, they check for both halt conditions: reaching 1, and repeating a number.

A simple test in Python to check if a number is happy:

defpdi_function(number,base:int=10):"""Perfect digital invariant function."""total=0whilenumber>0:total+=pow(number%base,2)number=number//basereturntotaldefis_happy(number:int)->bool:"""Determine if the specified number is a happy number."""seen_numbers=set()whilenumber>1andnumbernotinseen_numbers:seen_numbers.add(number)number=pdi_function(number)returnnumber==1

See also

Related Research Articles

2 (two) is a number, numeral and digit. It is the natural number following 1 and preceding 3. It is the smallest and only even prime number. Because it forms the basis of a duality, it has religious and spiritual significance in many cultures.

A palindromic number is a number that remains the same when its digits are reversed. In other words, it has reflectional symmetry across a vertical axis. The term palindromic is derived from palindrome, which refers to a word whose spelling is unchanged when its letters are reversed. The first 30 palindromic numbers are:

<span class="mw-page-title-main">Square number</span> Product of an integer with itself

In mathematics, a square number or perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 9 is a square number, since it equals 32 and can be written as 3 × 3.

In recreational mathematics, a repdigit or sometimes monodigit is a natural number composed of repeated instances of the same digit in a positional number system. The word is a portmanteau of "repeated" and "digit". Examples are 11, 666, 4444, and 999999. All repdigits are palindromic numbers and are multiples of repunits. Other well-known repdigits include the repunit primes and in particular the Mersenne primes.

73 (seventy-three) is the natural number following 72 and preceding 74. In English, it is the smallest natural number with twelve letters in its spelled out name.

300 is the natural number following 299 and preceding 301.

360 is the natural number following 359 and preceding 361.

500 is the natural number following 499 and preceding 501.

700 is the natural number following 699 and preceding 701.

3000 is the natural number following 2999 and preceding 3001. It is the smallest number requiring thirteen letters in English.

In mathematics, a harshad number in a given number base is an integer that is divisible by the sum of its digits when written in that base. Harshad numbers in base n are also known as n-harshad numbers. Harshad numbers were defined by D. R. Kaprekar, a mathematician from India. The word "harshad" comes from the Sanskrit harṣa (joy) + da (give), meaning joy-giver. The term "Niven number" arose from a paper delivered by Ivan M. Niven at a conference on number theory in 1977.

A Friedman number is an integer, which represented in a given numeral system, is the result of a non-trivial expression using all its own digits in combination with any of the four basic arithmetic operators (+, −, ×, ÷), additive inverses, parentheses, exponentiation, and concatenation. Here, non-trivial means that at least one operation besides concatenation is used. Leading zeros cannot be used, since that would also result in trivial Friedman numbers, such as 024 = 20 + 4. For example, 347 is a Friedman number in the decimal numeral system, since 347 = 73 + 4. The decimal Friedman numbers are:

In mathematics, the digit sum of a natural number in a given number base is the sum of all its digits. For example, the digit sum of the decimal number would be

A cyclic number is an integer for which cyclic permutations of the digits are successive integer multiples of the number. The most widely known is the six-digit number 142857, whose first six integer multiples are

In number theory, a Dudeney number in a given number base is a natural number equal to the perfect cube of another natural number such that the digit sum of the first natural number is equal to the second. The name derives from Henry Dudeney, who noted the existence of these numbers in one of his puzzles, Root Extraction, where a professor in retirement at Colney Hatch postulates this as a general method for root extraction.

In mathematics, a pandigital number is an integer that in a given base has among its significant digits each digit used in the base at least once. For example, 1234567890 is a pandigital number in base 10. The first few pandigital base 10 numbers are given by :

In number theory, a narcissistic number in a given number base is a number that is the sum of its own digits each raised to the power of the number of digits.

A sum-product number in a given number base is a natural number that is equal to the product of the sum of its digits and the product of its digits.

In number theory, the multiplicative digital root of a natural number in a given number base is found by multiplying the digits of together, then repeating this operation until only a single-digit remains, which is called the multiplicative digital root of . The multiplicative digital root for the first few positive integers are:

In number theory and mathematical logic, a Meertens number in a given number base is a natural number that is its own Gödel number. It was named after Lambert Meertens by Richard S. Bird as a present during the celebration of his 25 years at the CWI, Amsterdam.

References

  1. "Sad Number". Wolfram Research, Inc. Retrieved 16 September 2009.
  2. Gilmer, Justin (2013). "On the Density of Happy Numbers". Integers. 13 (2): 2. arXiv: 1110.3836 . Bibcode:2011arXiv1110.3836G.
  3. Sloane, N. J. A. (ed.). "SequenceA161872(Smallest unhappy number in base n)". The On-Line Encyclopedia of Integer Sequences . OEIS Foundation.
  4. Sloane, N. J. A. (ed.). "SequenceA035502(Lower of pair of consecutive happy numbers)". The On-Line Encyclopedia of Integer Sequences . OEIS Foundation. Retrieved 8 April 2011.
  5. Sloane, N. J. A. (ed.). "SequenceA072494(First of triples of consecutive happy numbers)". The On-Line Encyclopedia of Integer Sequences . OEIS Foundation. Retrieved 8 April 2011.
  6. Pan, Hao (2006). "Consecutive Happy Numbers". arXiv: math/0607213 .
  7. Sloane, N. J. A. (ed.). "SequenceA055629(Beginning of first run of at least n consecutive happy numbers)". The On-Line Encyclopedia of Integer Sequences . OEIS Foundation.
  8. Styer, Robert (2010). "Smallest Examples of Strings of Consecutive Happy Numbers". Journal of Integer Sequences . 13: 5. 10.6.3 via University of Waterloo. Cited in Sloane "A055629".
  9. Sloane, N. J. A. (ed.). "SequenceA068571(Number of happy numbers <= 10^n)". The On-Line Encyclopedia of Integer Sequences . OEIS Foundation.
  10. Chris K. Caldwell. "The Prime Database: 10150006 + 7426247 · 1075000 + 1". utm.edu.
  11. Chris K. Caldwell. "The Prime Database: 242643801 − 1". utm.edu.

Literature