A035497 Happy primes: primes that eventually reach 1 under iteration of "x -> sum of squares of digits of x".
7, 13, 19, 23, 31, 79, 97, 103, 109, 139, 167, 193, 239, 263, 293, 313, 331, 367, 379, 383, 397, 409, 487, 563, 617, 653, 673, 683, 709, 739, 761, 863, 881, 907, 937, 1009, 1033, 1039, 1093, 1151, 1277, 1303, 1373, 1427, 1447, 1481, 1487, 1511, 1607, 1663
Offset: 1
References
- R. K. Guy, Unsolved Problems Number Theory, Sect. E34.
Links
- Nathaniel Johnston, Table of n, a(n) for n = 1..10000
- Shyam Sunder Gupta, Happy Numbers, Exploring the Beauty of Fascinating Numbers, Springer (2025) Ch. 7, 209-222.
- Carlos Rivera, Puzzle 21. Happy primes, The Prime Puzzles and Problems Connection.
- Eric Weisstein's World of Mathematics, Happy Number
- Doctor Who, Episode 42
- Wikipedia, Happy number
- Wikipedia, Doctor Who, Episode 42
Programs
-
Mathematica
g[n_] := Total[ IntegerDigits[n]^2]; fQ[n_] := NestWhileList[g@# &, n, UnsameQ, All][[-1]] == 1; Select[Prime@ Range@ 300, fQ@# &] (* Robert G. Wilson v, Jan 03 2013 *) hpQ[p_]:=NestWhile[Total[IntegerDigits[#]^2]&,p,#!=1&,1,50]==1; Select[Prime[ Range[ 300]],hpQ] (* Harvey P. Dale, Jun 07 2022 *)
-
PARI
has(n)=while(n>6, n=norml2(digits(n))); n==1 is(n)=has(n) && isprime(n) \\ Charles R Greathouse IV, Dec 14 2015
-
Python
from sympy import isprime def swb(n): return sum(map(lambda x: x*x, map(int, str(n)))) def happy(bd): while bd not in [1, 4]: bd = swb(bd) # iterate to fixed point or cycle return bd == 1 def ok(n): return isprime(n) and happy(n) def aupto(n): return [k for k in range(1, n+1) if ok(k)] print(aupto(2012)) # Michael S. Branicky, Jul 13 2022
Extensions
More terms from Patrick De Geest, Oct 15 1999
Comments