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


int Pow, A, B, C, D, N;
[Pow:= [0, 1, 4, 27, 256, 3125];
for A:= 0 to 5 do
  for B:= 0 to 5 do
    for C:= 0 to 5 do
      for D:= 0 to 5 do
        [N:= A*1000 + B*100 + C*10 + D;
        if Pow(A) + Pow(B) + Pow(C) + Pow(D) = N then
          if N>=1 & N<= 5000 then
                [IntOut(0, N);  CrLf(0)];
        ];
]