There are only three numbers that can be written as the sum of fourth powers of their digits:
8208 ,9474 (the trivial case of number 1 excluded).
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.
FOR n = 1 TO 354294
s$ = LTRIM$(STR$(n))
tot = 0
FOR i = 1 TO LEN(s$)
d = VAL(MID$(s$, i, 1))
tot = tot + d * d * d * d * d
IF tot = n THEN PRINT n
The sum of these numbers is 443,840, and is in fact what is asked for. However, if we're to follow the 4th power example, we should subtract the trivial 1 to get 443,839, though the final, instructional, paragraph does not tell us explicitly to do this.
BTW, the 354294 in the program is 6*9^5 as the largest sum of fifth powers of six digits could be this. All sets of digits with more than six digits add up to a number with fewer than whatever number the fifth power total comes to.
Posted by Charlie
on 2012-08-30 14:31:37