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.


 
       PROGRAM-ID. NARCISSIST-NUMS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
 
           01 num-length PIC 9(2) value 0.
           01 in-sum PIC  9(9) value 0.
           01 counter PIC  9(9) value 0.
           01 current-number PIC  9(9) value 0.
           01 narcissist PIC Z(9).
           01 temp PIC  9(9) value 0.
           01 modulo PIC  9(9) value 0.
           01 answer PIC  9 .
 
       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
           DISPLAY "the first 20 narcissist numbers:" .
 
           MOVE 20 TO counter.
           PERFORM UNTIL counter=0
 
               PERFORM 000-NARCISSIST-PARA
 
                   IF answer = 1 
                       SUBTRACT 1 from counter
                       GIVING counter
                       MOVE current-number TO narcissist
                       DISPLAY narcissist
                   END-IF
 
                   ADD 1 TO current-number
 
               END-PERFORM
 
            STOP RUN.
 
       000-NARCISSIST-PARA.
 
             MOVE ZERO TO in-sum.
             MOVE current-number TO temp.
             COMPUTE num-length =1+  FUNCTION Log10(temp)
 
             PERFORM  UNTIL temp=0
 
                  DIVIDE temp BY 10 GIVING temp
                            REMAINDER  modulo
 
                  COMPUTE modulo=modulo**num-length
                  ADD modulo to in-sum GIVING in-sum
 
            END-PERFORM.
 
               IF current-number=in-sum
                   MOVE 1 TO answer
                   ELSE MOVE 0 TO answer
               END-IF.
 
       END PROGRAM NARCISSIST-NUMS.
 
 