Problem #30
Difficulty: 5%
Digit Fifth Powers
Solution Language: Java
The problem
Find the sum of all numbers that equal the sum of the fifth powers of their own digits (1 doesn’t count, since it isn’t a sum).
My solution
Brute force over 101 … 999,999. For each number I peel off digits with % 10, add Math.pow(digit, 5), and compare the total to the original.
A comment in the code explains the upper bound of a million: past that point the digit sum “simply cannot catch up”. To put numbers on it, a number with d ≥ 7 digits is at least 10ᵈ⁻¹, but its digit fifth-power sum is at most d × 9⁵ (413,343 for d = 7), which is far smaller.
Starting at 101 skips 1, which the problem excludes, along with the two-digit numbers, none of which qualify.