==

Factorion

A factorion is a natural number that equals the sum of the factorials of its decimal digits. 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 (sequence A014080 in OEIS).

Upper bound

If 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.

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

* factorion at daviddarling.info/encyclopedia

* factorion at Wolfram MathWorld

Retrieved from "http://en.wikipedia.org/"
All text is available under the terms of the GNU Free Documentation License

Index

Scientificlib.com
Scientificlib News