Sudal's Garage

Project Euler 30 본문

Programming/Project Euler - python

Project Euler 30

_Sudal 2019. 3. 18. 05:00

Question: 


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

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.


문제:

놀랍게도 각 자릿수의 네제곱의 합이 자기자신과 같은 수는 오로지 세 수 뿐이다.

1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44

1 = 14 은 합이라고 볼 수 없으므로 포함되지 않는다.

이 수들의 합은 1634 + 8208 + 9474 = 19316 이다.

각 자릿수의 다섯제곱의 합이 자기자신과 같은 수를 모두 찾아 그 합을 구하여라.


Solution:


print(sum([i for i in range(10,200000) if i == eval(" ** 5 +".join(list(str(i) + str(0))))]))


숫자를 str 형식으로 만들어주고, 그 사이사이에 ** 5 를 붙여 5제곱을 표현해준다. str(0)이 뒤에 붙은 이유는, 이것이 없다면 마지막 자리수의 5제곱은 빠지게 된다. 0 의 5제곱은 합에 영향을 주지 않는다.


2.42 초 걸렸다!




'Programming > Project Euler - python' 카테고리의 다른 글

Project Euler 32  (0) 2019.03.25
Project Euler 31  (0) 2019.03.24
Project Euler 29  (0) 2019.03.17
Project Euler 28  (0) 2019.03.16
Project Euler 26  (0) 2019.03.16