Factorion
From Wikipedia, the free encyclopedia
|
A factorion is a natural number that equals the sum of the factorials of its decimal digits. There are just four factorions and they are 1, 2, 145 and 40585. The proof that 145 is a factorion is 1! + 4! + 5! = 1 + 24 + 120 = 145. Upper boundIf n is a natural number of d digits that is a factorion, then 10d − 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. CodeSome 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 References |


