A   Narcissistic decimal number   is a non-negative integer,   



n


{\displaystyle n}

,   that is equal to the sum of the   



m


{\displaystyle m}

-th   powers of each of the digits in the decimal representation of   



n


{\displaystyle n}

,   where   



m


{\displaystyle m}

   is the number of digits in the decimal representation of   



n


{\displaystyle n}

.



Narcissistic (decimal) numbers are sometimes called   Armstrong   numbers, named after Michael F. Armstrong.

They are also known as   Plus Perfect   numbers.



An example

   if   



n


{\displaystyle n}

   is   153 
   then   



m


{\displaystyle m}

,   (the number of decimal digits)   is   3 
   we have    13 + 53 + 33   =   1 + 125 + 27   =   153  
   and so   153   is a narcissistic decimal number


Task

Generate and show here the first   25   narcissistic decimal numbers.



Note:   




0

1


=
0


{\displaystyle 0^{1}=0}

,   the first in the series.



See also

   the  OEIS entry:     Armstrong (or Plus Perfect, or narcissistic) numbers.
   MathWorld entry:   Narcissistic Number.
   Wikipedia entry:     Narcissistic number.


begin
    % print the first 25 narcissistic numbers                                 %
 
    integer array  power( 0 :: 9 );
    integer count, candidate, prevDigits, digits;
 
    power( 0 ) := 0;
    for i := 1 until 9 do power( i ) := 1;
 
    count      := 0;
    candidate  := 0;
    prevDigits := 0;
    digits     := 1;
 
    for d9 := 0 until 2 do begin
        if d9 > 0 and digits < 9 then digits := 9;
        for d8 := 0 until 9 do begin
            if d8 > 0 and digits < 8 then digits := 8;
            for d7 := 0 until 9 do begin
                if d7 > 0 and digits < 7 then digits := 7;
                for d6 := 0 until 9 do begin
                    if d6 > 0 and digits < 6 then digits := 6;
                    for d5 := 0 until 9 do begin
                        if d5 > 0 and digits < 5 then digits := 5;
                        for d4 := 0 until 9 do begin
                            if d4 > 0 and digits < 4 then digits := 4;
                            for d3 := 0 until 9 do begin
                                if d3 > 0 and digits < 3 then digits := 3;
                                for d2 := 0 until 9 do begin
                                    if d2 > 0 and digits < 2 then digits := 2;
                                    for d1 := 0 until 9 do begin
                                        integer number, sum;
                                        if prevDigits <> digits then begin
                                            % number of digits has increased %
                                            % - increase the powers          %
                                            prevDigits := digits;
                                            for i := 2 until 9 do power( i ) := power( i ) * i;
                                        end;
 
                                        % sum the digits'th powers of the    %
                                        % digits of candidate                %
                                        sum := power( d1 ) + power( d2 ) + power( d3 )
                                             + power( d4 ) + power( d5 ) + power( d6 )
                                             + power( d7 ) + power( d8 ) + power( d9 )
                                             ;
                                        if candidate = sum then begin
                                            % found another narcissistic    %
                                            % decimal number                %
                                            writeon( i_w := 1, s_w := 1, candidate );
                                            count := count + 1;
                                            if count >= 25 then goto done
                                        end;
                                        candidate := candidate + 1
                                    end d1;
                                end d2;
                            end d3;
                        end d4;
                    end d5;
                end d6;
            end d7;
        end d8;
    end d9;
done:
    write()
 
end.