Beispiel #1
0
def p021(N=10**4):
    table = [numty.sigma(f) - n for (n, f) in enumerate(utils.factortable(N))]
    acc = 0
    for n in range(1, N):
        if 0 < table[n] < N and table[table[n]] == n and table[n] != n:
            logger.debug('%d %d' % (n, table[n]))
            acc += n
    return acc
Beispiel #2
0
def p021(N=10 ** 4):
    table = [numty.sigma(f) - n for (n, f) in enumerate(utils.factortable(N))]
    acc = 0
    for n in range(1, N):
        if 0 < table[n] < N and table[table[n]] == n and table[n] != n:
            logger.debug("%d %d" % (n, table[n]))
            acc += n
    return acc
Beispiel #3
0
def p095(N=10**6):
    table = [numty.sigma(f)-n for n,f in enumerate(utils.factortable(N))]
    lengths = [-1 for n in table]
    for i in range(len(table)):
        chain = [i]
        j=table[i]
        while j < len(table) and j not in chain:
            chain.append(j)
            j = table[j]
        if j == i:
            lengths[i] = len(chain)
    return lengths.index(max(lengths))
Beispiel #4
0
def p095(N=10**6):
    table = [numty.sigma(f) - n for n, f in enumerate(utils.factortable(N))]
    lengths = [-1 for n in table]
    for i in range(len(table)):
        chain = [i]
        j = table[i]
        while j < len(table) and j not in chain:
            chain.append(j)
            j = table[j]
        if j == i:
            lengths[i] = len(chain)
    return lengths.index(max(lengths))
Beispiel #5
0
def p023():
    abundant = [n for (n,f) in enumerate(numty.factortable(LIMIT))
            if numty.sigma(f) > 2*n > 0]
    abundantset = set(abundant)

    def check_n(n):
        for a in abundant:
            if n-a in abundantset:
                return False
            if n-a < a:
                return True
    
    return sum(n for n in range(LIMIT+1) if check_n(n))
Beispiel #6
0
def p023():
    abundant = [
        n for (n, f) in enumerate(numty.factortable(LIMIT))
        if numty.sigma(f) > 2 * n > 0
    ]
    abundantset = set(abundant)

    def check_n(n):
        for a in abundant:
            if n - a in abundantset:
                return False
            if n - a < a:
                return True

    return sum(n for n in range(LIMIT + 1) if check_n(n))