Project Euler with Ruby on WSL [Problem 34]

時が経つのは早い

光陰矢の如し。

問題

Digit factorials

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.

私訳

各位の階乗

145 は興味深いことに、1! + 4! + 5! = 145 となる。

「各位の階乗の和が自身と等しい数」すべての和を求めよ

注意: 1! = 1, 2! = 2 はこれに含まないものとする

解答方針

問題30とよく似ている。 どこまで調べれば「すべて」になるのかが問題だ。

n 桁の10進数で考えれば  n \cdot 9! \lt 10^n - 1 となる最初の n を求めたい。

-1 は無視して 10 の対数を取ると  \log(n)+\log(9!) \approx \log(n) + 5.56 \lt n

n = 6 で成立することがわかる。