https://projecteuler.net/problem=34
def fact(n): if n <= 1: return 1 else: return n * fact(n - 1) candidates = [] n = 3 while True: # print "Analizyng", n n_str = str(n) partial_sum = 0 for digit in n_str: partial_sum += fact(int(digit)) if partial_sum == n: candidates.append(n) if n > 1000000: break n += 1 #print candidates print sum(candidates)