Project Euler with Ruby on WSL [Problem 30]
はあ30
年齢に近い大きさの整数をみると「ん?」ってなる時ありますよね
まぁ年齢を正確に思い出せるかは別問題だけど
問題
Digit fifth powers
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44
As 1 = 14 is not a sum it is not included.
The sum of these numbers is 1634 + 8208 + 9474 = 19316.
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
私訳
各位の5乗
10進表記した各位の4乗の和が、元の数自体に一致するのは以下の3例しかない。
1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44
なお 1 = 14 は自明だが、含めないものとする
「各位の5乗和がそれ自身と一致する数」すべての和を求めよ
解答方針
最終的には虱潰しに実行するが、探索範囲を制限したい。
d 桁の自然数 n を考えると で、その各位の5乗和 S は
S = n となりうる範囲を考えているので結局 となるような d の範囲を考えることになる
だから
よって d = 5 が確定。与えたのは上限だけなので、2 以上の範囲で調べる
と思ったんだけどなんか 6 桁の例が紛れてますね。うーーーーんなんで。まぁいいや