day1/exercise/aliquot.py
author Santosh G. Vattam <vattam.santosh@gmail.com>
Tue, 27 Apr 2010 12:14:30 +0530
changeset 386 a0bec380b44f
parent 380 669b72283b55
permissions -rw-r--r--
Major edits.

def aliquot(n):
    """returns the aliquot of a number which
    is defined as the sum of all the proper
    divisors of a number"""
    sum = 1
    i = 2

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

n = int(raw_input('Enter a number? '))
print aliquot(n)