Sudal's Garage

Project Euler 34 본문

Programming/Project Euler - python

Project Euler 34

_Sudal 2019. 3. 27. 05:00

Question: 


145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

Find the sum of all numbers which are equal to the sum of the factorial of their digits.

Note: as 1! = 1 and 2! = 2 are not sums they are not included.


문제:


145는 '희한한 성질'이 있는 숫자인데, 1! + 4! + 5! = 1 + 24 + 120 = 145 와 같이 각 자리 숫자의 팩토리얼을 더하면 자기 자신이 된다.

이러한 '희한한 성질'이 있는 모든 숫자의 합을 구하여라.

주의: 1! = 1 이고 2! = 2 인데 이것들은 합이 아니므로 포함되지 않는다.


Solution:


from math import factorial import time result = list() start = time.time() for i in range(3,100000): summ = 0 for j in list(str(i)): summ += factorial(int(j)) if summ == i: result.append(i) print(sum(result)) print("Found in ...%.3fs" %(time.time() - start))


무난하다.

0.25 초 걸렸다!




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

Project Euler 36  (0) 2019.03.29
Project Euler 35  (0) 2019.03.28
Project Euler 33  (0) 2019.03.26
Project Euler 32  (0) 2019.03.25
Project Euler 31  (0) 2019.03.24