eBash

It is not the mountain we conquer but ourselves

Project Euler Problem 34

| Comments

Table of Contents

1 Problem

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

Find the sum of all numbers which are equal to the sum of the factorial of their digits.

Note: as 1! = 1 and 2! = 2 are not sums they are not included.

2 Solution

问题的关键只要找出上界就行.跟Project Euler Problem 30 类似,设上界为n位数字,则

\(10^n\) < 9! * n

易知n最大为7,更确切的说其上界为 9! * n = 2540160;
剩下的就是遍历查找了

3 Answer

40730

Source:C++

Comments