Problem 30
- 投稿者 : rei
Original
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
1634 = 1^4 + 6^4 + 3^4 + 4^4
8208 = 8^4 + 2^4 + 0^4 + 8^4
9474 = 9^4 + 4^4 + 7^4 + 4^4
As 1 = 1^4 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.
和訳
驚くべきことに, 各桁を4乗した和が元の数と一致する数は3つしかない.
1634 = 1^4 + 6^4 + 3^4 + 4^4
8208 = 8^4 + 2^4 + 0^4 + 8^4
9474 = 9^4 + 4^4 + 7^4 + 4^4
ただし, 1=1^4は含まないものとする. この数たちの和は 1634 + 8208 + 9474 = 19316 である.各桁を5乗した和が元の数と一致するような数の総和を求めよ
当てにならないソースコード(C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | using System; namespace ProjectEuler { class Problem30 : Problem{ ulong[] pow5 = new ulong[10]; public Problem30() { for (ulong i = 0; i < 10; i++) pow5[i] = i * i * i * i * i; ulong answer = 0; ulong max = 0; for (ulong i = 1; ; i++) { if ((ulong)Math.Pow(10, i) < pow5[9] * i) max = pow5[9] * i; else break; } for (ulong i = 2; i < max; i++) { answer += Match(i); } Console.WriteLine("> " + answer); } ulong Match(ulong number) { ulong num = number; ulong total = 0; for (;num > 0;) { total += pow5[num % 10]; num /= 10; } return number == total ? number : 0; } } } |
上限を求められればあとは作業です。

rei@sikios.com
コメントはまだありません。