

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


100 DIM FACT(12)
110 FACT(0) = 1
120 FOR N = 1 TO 11
130     FACT(N) = FACT(N - 1) * N
140 NEXT 
200 FOR B = 9 TO 12
210     PRINT "THE FACTORIONS ";
215     PRINT "FOR BASE "B" ARE:"
220     FOR I = 1 TO 1499999
230         SUM = 0
240         FOR J = I TO 0 STEP 0
245             M =  INT (J / B)
250             D = J - M * B
260             SUM = SUM + FACT(D)
270             J = M
280         NEXT J
290         IF SU = I THEN  PRINT I" ";
300     NEXT I
310     PRINT : PRINT 
320 NEXT B