31 lines
864 B
Python
31 lines
864 B
Python
|
|
from functools import reduce
|
|
|
|
def calc(k):
|
|
eq = []
|
|
not_one = 2 # how many numbers that != 1
|
|
while True:
|
|
lst = [2] * not_one
|
|
while True:
|
|
diff = sum(lst) + (k - not_one) - reduce(lambda x, y: x * y, lst, 1)
|
|
if not diff:
|
|
eq.append((sum(lst) + k - not_one, lst))
|
|
break
|
|
elif diff > 0:
|
|
lst[0] += 1
|
|
continue
|
|
for i in range(1, len(lst)):
|
|
if lst[i] != lst[0]:
|
|
lst[:i + 1] = [lst[i] + 1] * (i + 1)
|
|
break
|
|
else:
|
|
break
|
|
not_one += 1
|
|
if 2 ** not_one > 2 * not_one + k - not_one:
|
|
break
|
|
print(k, len(eq), min(eq))
|
|
return min(eq)
|
|
|
|
lll = list(map(lambda x: calc(x), range(2, 12)))
|
|
print(sum(map(lambda x: x[0], lll)))
|