day1/exercise/aliquot.py
author Santosh G. Vattam <vattam.santosh@gmail.com>
Tue, 30 Mar 2010 11:29:26 +0530
changeset 383 26294a5b856b
parent 380 669b72283b55
permissions -rw-r--r--
Added new image files needed for compilation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
def aliquot(n):
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 354
diff changeset
     2
    """returns the aliquot of a number which
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 354
diff changeset
     3
    is defined as the sum of all the proper
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 354
diff changeset
     4
    divisors of a number"""
94
8c92864c184b Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 64
diff changeset
     5
    sum = 1
8c92864c184b Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 64
diff changeset
     6
    i = 2
8c92864c184b Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 64
diff changeset
     7
354
5dc6c3673f9d Changes made during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents: 94
diff changeset
     8
    while i * i < n: 
64
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
        if n % i == 0:
94
8c92864c184b Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 64
diff changeset
    10
            sum += i + (n / i)
8c92864c184b Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 64
diff changeset
    11
        i += 1
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 354
diff changeset
    12
    if i*i == n: sum += i
64
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
    return sum
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
94
8c92864c184b Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 64
diff changeset
    15
n = int(raw_input('Enter a number? '))
8c92864c184b Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 64
diff changeset
    16
print aliquot(n)