day1/exercise/aliquot.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Tue, 29 Dec 2009 19:01:43 +0530
changeset 332 f2ca851199d4
parent 94 8c92864c184b
child 354 5dc6c3673f9d
permissions -rw-r--r--
Changed few questions in day1quiz1 and added day 2 quiz.

def is_perfect_square(n):
    i = 1
    while i * i < n:
        i += 1
    return i * i == n, i

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

    is_ps, root = is_perfect_square(n)
    while i < root:
        if n % i == 0:
            sum += i + (n / i)
        i += 1
    return sum

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