

Definition

A factorion is a natural number that equals the sum of the factorials of its digits.



Example
 
145   is a factorion in base 10 because:


          1! + 4! + 5!   =   1 + 24 + 120   =   145 





It can be shown (see talk page) that no factorion in base 10 can exceed   1,499,999.



Task

Write a program in your language to demonstrate, by calculating and printing out the factorions, that:

   There are   3   factorions in base   9
   There are   4   factorions in base 10
   There are   5   factorions in base 11 
   There are   2   factorions in base 12     (up to the same upper bound as for base 10)


See also

 Wikipedia article
 OEIS:A014080 - Factorions in base 10
 OEIS:A193163 - Factorions in base n


Dim As Integer fact(12), suma, d, j
fact(0) = 1
For n As Integer = 1 To 11
    fact(n) = fact(n-1) * n
Next n
For b As Integer = 9 To 12
    Print "Los factoriones para base " & b & " son: "
    For i As Integer = 1 To 1499999
        suma = 0
        j = i
        While j > 0
            d = j Mod b
            suma += fact(d)
            j \= b
        Wend
        If suma = i Then Print i & " ";
    Next i
    Print : Print
Next b
Sleep