day1/exercise/aliquot.py
changeset 380 669b72283b55
parent 354 5dc6c3673f9d
equal deleted inserted replaced
379:682b6f66fe11 380:669b72283b55
     1 
       
     2 def aliquot(n):
     1 def aliquot(n):
       
     2     """returns the aliquot of a number which
       
     3     is defined as the sum of all the proper
       
     4     divisors of a number"""
     3     sum = 1
     5     sum = 1
     4     i = 2
     6     i = 2
     5 
     7 
     6     while i * i < n: 
     8     while i * i < n: 
     7         if n % i == 0:
     9         if n % i == 0:
     8             sum += i + (n / i)
    10             sum += i + (n / i)
     9         i += 1
    11         i += 1
    10     if n % i == 0: sum += i
    12     if i*i == n: sum += i
    11     return sum
    13     return sum
    12 
    14 
    13 n = int(raw_input('Enter a number? '))
    15 n = int(raw_input('Enter a number? '))
    14 print aliquot(n)
    16 print aliquot(n)