Digit fifth powers :Problem 30 : Project Euler
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
To get hold of the upper limit see
Python Code
def digitFifthPowers():
number = 10
sumNumbers = 0
digitfifthsum = 0
while number < 7*9**5+1:
strnumber = str(number)
digitfifthsum = 0
for i in range(len(strnumber)):
digitfifthsum = digitfifthsum + int(strnumber[i])**5
if digitfifthsum > number:
break
if digitfifthsum == number:
sumNumbers = sumNumbers + number
print number,"Sum of the digits raised 5 is equal to the number itself"
number = number + 1
print "Required Sum is",sumNumbers
digitFifthPowers()
1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44
As 1 = 14 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.
To get hold of the upper limit see
Digit factorials : Problem 34 : Project Euler
Python Code
def digitFifthPowers():
number = 10
sumNumbers = 0
digitfifthsum = 0
while number < 7*9**5+1:
strnumber = str(number)
digitfifthsum = 0
for i in range(len(strnumber)):
digitfifthsum = digitfifthsum + int(strnumber[i])**5
if digitfifthsum > number:
break
if digitfifthsum == number:
sumNumbers = sumNumbers + number
print number,"Sum of the digits raised 5 is equal to the number itself"
number = number + 1
print "Required Sum is",sumNumbers
digitFifthPowers()
No comments:
Post a Comment