day1/exercise/amicable.py
author Puneeth Chaganti <punchagan@fossee.in>
Tue, 27 Oct 2009 19:14:55 +0530
changeset 210 2d41487bc6fe
parent 94 8c92864c184b
child 380 669b72283b55
permissions -rw-r--r--
Added an image for scatter plot of L vs T^2.

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

amicable = []

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