def divisor_list(n): """Return the list of divisors of the given integer. >>> divisor_list(24) [1, 2, 3, 4, 6, 8, 12, 24] >>> divisor_list(30850) [1, 2, 5, 10, 25, 50, 617, 1234, 3085, 6170, 15425, 30850] >>> divisor_list(math.factorial(5)) [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120] """ factors = A5.factor_map(n) factor_powers = (tuple(factor ** exp for exp in range(multiple + 1)) for factor, multiple in factors.items()) return sorted(reduce(operator.mul, data) for data in itertools.product(*factor_powers))
def divisor_count(n): """Compute the number of divisors for the given integer. >>> divisor_count(7) 2 >>> divisor_count(12) 6 >>> divisor_count(36) 9 >>> divisor_count(math.factorial(5)) 16 >>> divisor_count(math.factorial(15)) 4032 """ # Each divisor is a product of multiples of each prime factor. factor_counts = A5.factor_map(n).values() # Compute the product of factor counts, incrementing since a factor may # be taken to the 0th power. return reduce(operator.mul, (1 + count for count in factor_counts), 1)