Exemplo n.º 1
0
def generate_divisors(n):
    factors = to_powers(factorize(n))
    nfactors = len(factors)
    f = [0] * nfactors
    while True:
        yield reduce(lambda x, y: x*y,
                     [factors[x][0]**f[x] for x in range(nfactors)], 1)
        i = 0
        while True:
            f[i] += 1
            if f[i] <= factors[i][1]:
                break
            f[i] = 0
            i += 1
            if i >= nfactors:
                return
Exemplo n.º 2
0
def divs(n):
    powers = to_powers(factorize(n))
    # powers = [(a,x), (b,y), (c,z)] so that n = a^x * b^y * c^z
    divisors_count = reduce(lambda x, y: x*y, (f[1]+1 for f in powers))
    return divisors_count