summaryrefslogtreecommitdiff
path: root/day1/exercise/aliquot.py
blob: 96ea916f3bfc4f763fe8040c1d42c773f3032de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)