author | Santosh G. Vattam <vattam.santosh@gmail.com> |
Wed, 18 Nov 2009 19:26:48 +0530 | |
changeset 314 | c9f05808e1c4 |
parent 94 | 8c92864c184b |
child 354 | 5dc6c3673f9d |
permissions | -rw-r--r-- |
94
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
1 |
def is_perfect_square(n): |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
2 |
i = 1 |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
3 |
while i * i < n: |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
4 |
i += 1 |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
5 |
return i * i == n, i |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
6 |
|
64
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
def aliquot(n): |
94
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
8 |
sum = 1 |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
9 |
i = 2 |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
10 |
|
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
11 |
is_ps, root = is_perfect_square(n) |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
12 |
while i < root: |
64
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
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
|
14 |
sum += i + (n / i) |
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
15 |
i += 1 |
64
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
return sum |
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
|
94
8c92864c184b
Almost last set of official solutions and final quiz.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
64
diff
changeset
|
18 |
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
|
19 |
print aliquot(n) |