## Project Euler #30

Problem: Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

Answer: **443839**

Solution:

My first pass was to check all numbers between 2 and 1 million. Then I realized that I could reduce the range. The max value for a digit is 9^5 (59049) and the max number could be 59049 times number of digits. This is more of a brute force. I’m sure there is a better way to get down the max range. I’ve reused my ToDigits extension method.

var x = Enumerable.Range(2, 295245) .Where(pArg => pArg.ToDigits().Sum(pArg1 => Math.Pow(pArg1, 5)) == pArg) .Select(pArg => pArg); var lAnswer = x.Sum();

Time: 930 ms

Advertisements

## Leave a Reply