equal
deleted
inserted
replaced
1 import math |
1 def is_perfect_square(n): |
|
2 i = 1 |
|
3 while i * i < n: |
|
4 i += 1 |
|
5 return i * i == n, i |
2 |
6 |
3 def aliquot(n): |
7 def aliquot(n): |
4 sum = 0 |
8 sum = 1 |
5 for i in range(1, int(math.sqrt(n))+1): |
9 i = 2 |
|
10 |
|
11 is_ps, root = is_perfect_square(n) |
|
12 while i < root: |
6 if n % i == 0: |
13 if n % i == 0: |
7 sum += i + n/i |
14 sum += i + (n / i) |
|
15 i += 1 |
8 return sum |
16 return sum |
9 |
17 |
10 amicable = [] |
18 amicable = [] |
11 for n in range(10000, 100000): |
19 |
|
20 n = 1000 |
|
21 while n < 10000: |
12 m = aliquot(n) |
22 m = aliquot(n) |
13 if aliquot(m) == n: |
23 if m > n and aliquot(m) == n: |
14 amicable.append((m, n)) |
24 print m, n |
15 |
25 n += 1 |
16 print amicable |
|
17 |
|
18 # please please please profile this. |
|