day1/exercise/amicable.py
author Puneeth Chaganti <punchagan@gmail.com>
Thu, 09 Dec 2010 18:39:26 +0530
branchscipyin2010
changeset 441 9d9e4026238f
parent 380 669b72283b55
permissions -rw-r--r--
Changed session-2 - now uses loadtxt.

def aliquot(n):
    sum = 1
    i = 2

    while i * i  < n:
        if n % i == 0:
            sum += i + (n / i)
        i += 1
    return sum

amicable = []

n = 1000
while n < 10000:
    m = aliquot(n)
    if m > n and aliquot(m) == n:
        print m, n
    n += 1