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.


' normal version: 14-03-2017
' compile with: fbc -s console
' can go up to 18 digits (ulongint is 64bit), above 18 overflow will occur
 
Dim As Integer n, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, a, b
Dim As Integer d()
Dim As ULongInt d2pow(0 To 9) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim As ULongInt x
Dim As String str_x
 
For n = 1 To 7
  For n9 = n To 0 Step -1
    For n8 = n-n9 To 0 Step -1
      For n7 = n-n9-n8 To 0 Step -1
        For n6 = n-n9-n8-n7 To 0 Step -1
          For n5 = n-n9-n8-n7-n6 To 0 Step -1
            For n4 = n-n9-n8-n7-n6-n5 To 0 Step -1
              For n3 = n-n9-n8-n7-n6-n5-n4 To 0 Step -1
                For n2 = n-n9-n8-n7-n6-n5-n4-n3 To 0 Step -1
                  For n1 = n-n9-n8-n7-n6-n5-n4-n3-n2 To 0 Step -1
                    n0 = n-n9-n8-n7-n6-n5-n4-n3-n2-n1
 
                    x = n1 + n2*d2pow(2) + n3*d2pow(3) + n4*d2pow(4) + n5*d2pow(5)_
                           + n6*d2pow(6) + n7*d2pow(7) + n8*d2pow(8) + n9*d2pow(9)
 
                    str_x = Str(x)
                    If Len(str_x) = n Then
 
                      ReDim d(10)
                      For a = 0 To n-1
                        d(Str_x[a]- Asc("0")) += 1
                      Next a
 
                      If n0 = d(0) AndAlso n1 = d(1) AndAlso n2 = d(2) AndAlso n3 = d(3)_
                                   AndAlso n4 = d(4) AndAlso n5 = d(5) AndAlso n6 = d(6)_
                                   AndAlso n7 = d(7) AndAlso n8 = d(8) AndAlso n9 = d(9) Then
                        Print x
                      End If
                    End If
 
                  Next n1
                Next n2
              Next n3
            Next n4
          Next n5
        Next n6
      Next n7
    Next n8
  Next n9
 
  For a As Integer = 2 To 9
    d2pow(a) = d2pow(a) * a
  Next a
 
Next n
 
' empty keyboard buffer 
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End