-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP74.py
36 lines (29 loc) · 765 Bytes
/
P74.py
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
from infgeoax import factorial
factorials = [factorial(x) for x in range(10)]
cache = {}
blackholes = {169: 2, 363601: 2, 1454: 2, 871: 1, 45361: 1, 872: 1, 45362: 1, 1: 0, 2: 0, 145: 0, 40585: 0}
chains = {}
def f(n):
if cache.has_key(n):
return cache[n]
else:
s = sum([factorials[int(c)] for c in "%d" % n])
cache[n] = s
return s
for j in range(1000000):
chain = 1
i = j
while True:
if blackholes.has_key(i):
chain += blackholes[i]
chains[j] = chain
break
i = f(i)
if chains.has_key(i):
chain += chains[i]
chains[j] = chain
break
else:
chain += 1
if chain==60:
print j, chain