Exemple #1
0
def shareDivisors(n1, n2):
    smallest = n1 if n1 < n2 else n2
    largest = n2 if n1 < n2 else n1
    for d in [d for d in divisors(smallest, True) if d > 1]:
        if largest % d == 0:
            return True
    return False
Exemple #2
0
def getDivisors(n, known = dict()):
    if n in known:
        return known[n]

    d = list(divisors(n, True))
    known[n] = d
    return d
Exemple #3
0
def challenge021():

    maximum = 10000
    total = 0
    dict = {}
    for a in xrange(1, maximum):
        # Get the divisors total
        b = 0
        for d in divisors(a, False):
            b += d

        if a != b:        
            # Is the number already defined?
            if dict.has_key(b):
                if dict[b] == a:
                    # Add the pair
                    total += a + b

        # Add the sum to the dictionary
        dict[a] = b

    return total
Exemple #4
0
def squareSum(n):
    return sum(i**2 for i in divisors(n, True))