import heapq as hq
def closure(xs, M):
q = xs[:]
seen = set()
hq.heapify(q)
for _ in range(M):
if len(q) > 0:
y = hq.heappop(q)
if not y in seen:
for x in xs:
hq.heappush(q, x * y)
xs.append(y)
seen.add(y)
return xs
# print(closure([3, 33], 50))
# # res = 33
# xs = [33, 35937, 99, 3, 3267, 1089, 107811, 1185921, 9801, 297, 891]
res = 2, 3, 7, 76, 82, 20, 26, 35, 37, 46
xs = [2,3 ,5]
def closure(xs, M):
q = xs[:]
hq.heapify(q)
seen = set()
b = False
while 1:
y = hq.heappop(q)
if not y in seen:
if y > M:
break
for x in xs:
hq.heappush(q, x * y)
xs.append(y)
seen.add(y)
return xs
print(closure(xs, 1000))
To embed this program on your website, copy the following code and paste it into your website's HTML: