-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem0034.py
More file actions
49 lines (39 loc) · 1.26 KB
/
Problem0034.py
File metadata and controls
49 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Enonce = """
Digit factorials
Problem 34
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.
"""
import EulerTools
import math
def main():
print(40*"=")
print(Enonce)
print(40*"-")
# find max possible digits
max_number = 10
for digits in range(2, 100):
if math.log10(math.factorial(9)*digits) < (digits-1):
break
max_number = math.factorial(9)*digits
print(f"Maximum possible number = {max_number}")
# find solution
size = 2
Solution = 0
for number in range (10, max_number+1):
_sum = 0
for digit in str(number):
_sum += math.factorial( int(digit) )
if _sum > number:
break
if _sum == number:
print(f"{number} is equal to the sum of the factorial of their digits.")
Solution += number
print(f"The sum of all numbers which are equal to the sum of the factorial of their digits is {Solution}")
print(40*"-")
print(f"Solution = {Solution}")
print(40*"=")
if __name__ == "__main__":
# execute only if run as a script
main()