A Munchausen number is a natural number n the sum of whose digits (in base 10), each raised to the power of itself, equals n.

(Munchausen is also spelled: Münchhausen.)

For instance:    3435 = 33 + 44 + 33 + 55 



Task
Find all Munchausen numbers between   1   and   5000.



Also see

 The OEIS entry:  A046253
 The Wikipedia entry:  Perfect digit-to-digit invariant, redirected from Munchausen Number


EnableExplicit
Declare main()
 
If OpenConsole("Munchausen_numbers")
  main() : Input() : End
EndIf
 
Procedure main()
  Define i.i,
         sum.i,
         number.i,
         digit.i  
  For i = 1 To 5000
    sum = 0
    number = i
    While number > 0
      digit = number % 10
      sum + Pow(digit, digit)
      number / 10
    Wend  
    If sum = i
      PrintN(Str(i))
    EndIf
  Next
EndProcedure