首页 | 主题 | 图库 | 问答 | 文摘 | 原创 | 百科

历史 | 地理 | 人物 | 艺术 | 体育 | 科学 | 音乐 | 电影 | 信息技术 | 世界遗产

 开放、中立,源自维基百科

Personal tools

Factorion

From Wikipedia, the free encyclopedia

Jump to: navigation, search

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 bound

If n is a natural number of d digits that is a factorion, then 10d − 1n ≤ 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

References

AD Links