Euler problem 30 is another number crunching problem that deals with numbers to the power of five. Two other Euler problems dealt with raising numbers to a power. The previous problem looked at permutations of powers and problem 16 asks for the sum of the digits of . Euler Problem 24 discusses lexicographic permutations.

Numberphile has a nice video about a trick to quickly calculate the fifth root of a number that makes you look like a mathematical wizard.

## Euler Problem 30 Definition

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

As is not a sum, it is not included.

The sum of these numbers is . Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

## Proposed Solution

The problem asks for a brute-force solution but we have a halting problem. How far do we need to go before we can be certain there are no sums of fifth power digits? The highest digit is and , which has five digits. If we then look at , which has six digits and a good endpoint for the loop. The loop itself cycles through the digits of each number and tests whether the sum of the fifth powers equals the number. Download the most recent version of this code on GitHub.

largest &amp;lt;- 6 * 9^5 answer &amp;lt;- 0 for (n in 2:largest) { power.sum &amp;lt;-0 i &amp;lt;- n while (i &amp;gt; 0) { d &amp;lt;- i %% 10 i &amp;lt;- floor(i / 10) power.sum &amp;lt;- power.sum + d^5 } if (power.sum == n) { print(n) answer &amp;lt;- answer + n } } print(answer)

## 2 Replies to “Digit fifth powers: Euler Problem 30”