- Factorion
A factorion is a
natural number that equals the sum of thefactorial s of itsdecimal digit s. For example, 145 is a factorion because 1! + 4! + 5! = 1 + 24 + 120 = 145.There are just four factorions and they are 1, 2, 145 and 40585 OEIS|id=A014080.
Upper bound
If "n" is a natural number of "d" digits that is a factorion, then 10"d" − 1 ≤ "n" ≤ 9!"d" and this fails to hold for "d" ≥ 8. Thus "n" has 7 digits at most and the first upper bound is 9,999,999. But the maximum sum of factorials of digits for a 7 digit number is 9!7 = 2540160, which is the second upper bound.
Code
Some Haskell code to compute factorions. Be sure to compile it with -O2 or your memory will be exhausted.
main = print $ filter (isFactorion 10) [1..2540160] factList = scanl (*) 1 [1..] quickFact n = factList !! n digitlist 0 _ = [] digitlist num base = let digit = mod num base in digit : digitlist (div (num - digit) base) base sumOfFactOfDigits base n = sum $ map quickFact $ digitlist n base isFactorion base n = n = sumOfFactOfDigits base n
And the code to compute the list of all factorions.
import Data.Char (digitToInt) main = print $ [i | i <- [1..2540160] , i = (sum $ map (i -> product [1..i] ) $ map digitToInt $ show i)]
References
* [http://www.daviddarling.info/encyclopedia/F/factorion.html factorion at daviddarling.info/encyclopedia]
* [http://mathworld.wolfram.com/Factorion.html factorion at Wolfram MathWorld]
Wikimedia Foundation. 2010.