51 lines
1.1 KiB
Python

from functools import reduce
class Num:
n = 0
l = []
over = False
def __init__(self, limit):
if limit < 2:
self.over = True
self.num = limit
self.l = [1] * limit
self.l[:2] = [2, 2]
def multi(self):
return reduce(lambda x, y: x * y, self.l, 1)
def add(self):
return sum(self.l)
def is_overload(self):
return self.multi() > self.add()
def inc(self):
if self.over:
return
if not self.is_overload():
self.l[0] += 1
else:
for i in range(len(self.l)):
if self.l[i + 1] < self.l[i]:
self.l[i + 1] += 1
self.l[:i] = [self.l[i + 1]] * (i + 1)
if self.is_overload():
self.over = True
def eq(self):
return self.multi() == self.add()
def get_min(self):
while not self.eq():
self.inc()
if self.over:
return NULL
return self.add()
for x in range(3, 20):
f = Num(x)
print(x, f.get_min())