%I M0487 #54 Jan 16 2022 19:48:26
%S 1,2,3,4,5,6,7,8,9,24,43,63,89,132,135,153,175,209,224,226,262,264,
%T 267,283,332,333,334,357,370,371,372,373,374,375,376,377,378,379,407,
%U 445,463,518,598,629,739,794,849,935,994,1034
%N Handsome numbers: sum of positive powers of its digits; a(n) = Sum_{i=1..k} d[i]^e[i] where d[1..k] are the decimal digits of a(n), e[i] > 0.
%C The previous name was "Powerful numbers, Definition (2). Cf. A001694, A023052. - _N. J. A. Sloane_, Jan 16 2022
%C J. Randle has suggested the name "powerful numbers" for the perfect digital invariants A023052, equal to the sum of a fixed power of the digits. However, "powerful" usually refers to a prime factorization related property, cf. A001694 (and references there as well as on the MathWorld page). C. Rivera has suggested the name "handsome" for these numbers (in view of narcissistic numbers A005188) in his prime puzzle #15: see also contributed comments concerning terminology on that page. - _M. F. Hasler_, Nov 21 2019
%D N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
%H David W. Wilson, <a href="/A007532/b007532.txt">Table of n, a(n) for n = 1..10000</a>
%H Giovanni Resta, <a href="http://www.numbersaplenty.com/set/d-powerful_number/">d-powerful numbers</a>, the 30067 terms and sums up to 10^6.
%H Carlos Rivera, <a href="https://www.primepuzzles.net/puzzles/puzz_015.htm">Puzzle 15.- Narcissistic and Handsome Primes</a>, The Prime Puzzles and Problems Connection.
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/PowerfulNumber.html">Powerful Number</a>.
%H <a href="/index/Pow#powerful">Index entries for sequences related to powerful numbers</a>
%F If n = d_1 d_2 ... d_k in decimal, then there are integers m_1, m_2, ..., m_k > 0 such that n = d_1^m_1 + ... + d_k^m_k.
%e 43 = 4^2 + 3^3 is OK; 254 = 2^7 + 5^3 + 4^0 is not OK since one of the powers is 0.
%p N:= 10000; # to get all entries <= N
%p Sums:= proc(L,N)
%p option remember;
%p local x1,L1;
%p x1:= L[1];
%p if x1 = 1 then L1:= {1}
%p else L1:= {seq(x1^j,j=1..floor(log[x1](N)))};
%p fi;
%p if nops(L) = 1 then L1
%p else select(`<=`,{seq(seq(a+b,a=L1),b=Sums(L[2..-1],N))},N)
%p fi
%p end proc;
%p filter:= proc(x,N)
%p local L;
%p L:= sort(subs(0=NULL,convert(x,base,10))) ;
%p member(x, Sums(L,N));
%p end proc;
%p A007532:= select(filter,[$1..N],N); # _Robert Israel_, Apr 13 2014
%t Select[Range@1000,(s=#;MemberQ[Total/@(a^#&/@Tuples[Range@If[#==1||#==0,1,Floor[Log[#,s]]]&/@(a=IntegerDigits[s])]),s])&] (* _Giorgos Kalogeropoulos_, Aug 18 2021 *)
%o (Haskell)
%o a007532 n = a007532_list !! (n-1)
%o a007532_list = filter f [1..] where
%o f x = g x 0 where
%o g 0 v = v == x
%o g u v = if d <= 1 then g u' (v + d) else v <= x && h d
%o where h p = p <= x && (g u' (v + p) || h (p * d))
%o (u', d) = divMod u 10
%o -- _Reinhard Zumkeller_, Jun 02 2013
%o (Python)
%o from itertools import count, takewhile
%o def cands(n, d):
%o return takewhile(lambda x: x<=n, (d**i for i in count(1)))
%o def handsome(s, t):
%o if s == "":
%o return t == 0
%o if s[0] in "01":
%o return handsome(s[1:], t - int(s[0]))
%o return any(handsome(s[1:], t - p) for p in cands(t, int(s[0])))
%o def ok(n):
%o return n and handsome(str(n), n)
%o print(list(filter(ok, range(1035)))) # _Michael S. Branicky_, Aug 18 2021
%Y Cf. A001694, A005934, A005188, A003321, A014576, A023052, A046074, A050240 (>= 2 reps.), A050241.
%Y Different from A061862.
%K base,nonn,nice
%O 1,2
%A _N. J. A. Sloane_, _Robert G. Wilson v_