assert len(limits) >= num - 1
limits = limits[:num-1] + [float("inf")]
factors = np.ones(num, dtype=int)
while True:
// Calculate the last factor.
factors[-1] = idivc(value, np.prod(factors[:-1]))
if np.prod(factors) == value \
and np.all(np.less(factors, limits)):
yield tuple(np.copy(factors))
// Update the first n - 1 factor combination, backwards.
After Change
// Calculate the last factor.
factors[-1] = idivc(value, prod(factors[:-1]))
if prod(factors) == value \
and all(f <= l for f, l in zip(factors, limits)):
yield tuple(factors)
// Update the first n - 1 factor combination, backwards.