author | Christopher Burns <chris.d.burns@gmail.com> |
Sun, 20 Jun 2010 22:50:03 -0700 | |
branch | scipy2010 |
changeset 414 | 68ef3dced7a0 |
parent 380 | 669b72283b55 |
permissions | -rw-r--r-- |
64
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
import math |
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
|
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
def aliquot(n): |
380
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
4 |
sum = 1 |
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
5 |
i = 2 |
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
6 |
|
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
7 |
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
|
8 |
if n % i == 0: |
380
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
9 |
sum += i + (n / i) |
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
10 |
i += 1 |
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
11 |
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
|
12 |
return sum |
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
|
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
amicable = [] |
380
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
15 |
for n in range(1000, 10000): |
64
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
m = aliquot(n) |
380
669b72283b55
Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
64
diff
changeset
|
17 |
if m > n and aliquot(m) == n: |
64
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
amicable.append((m, n)) |
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
|
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
print amicable |
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
|
333092b68926
Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
# please please please profile this. |