forked from nayuki/Project-Euler-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp074.py
More file actions
38 lines (28 loc) · 664 Bytes
/
p074.py
File metadata and controls
38 lines (28 loc) · 664 Bytes
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
#
# Solution to Project Euler problem 74
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
import math
def compute():
LIMIT = 10**6
ans = sum(1 for i in range(LIMIT) if get_chain_length(i) == 60)
return str(ans)
def get_chain_length(n):
seen = set()
while True:
seen.add(n)
n = factorialize(n)
if n in seen:
return len(seen)
def factorialize(n):
result = 0
while n != 0:
result += FACTORIAL[n % 10]
n //= 10
return result
FACTORIAL = [math.factorial(i) for i in range(10)]
if __name__ == "__main__":
print(compute())