Problem 21

completed December 4, 2011

Comments

This one only took a couple of tries. The toughest part really is reading the directions carefully. First time through I missed the a does not equal b requirement. Surprisingly, this made a big difference in the final total.

Code

from time import time
start_time= time()
print """Process started
----------"""

def d(n):
	a = 0
	for i in range(1, n):
		if n%i == 0:
			a = a + i
	return a

sum = 0
for s in range(1, 10**4):
	print s
	if (d(d(s)) == s) and (d(s) != s):
		sum = sum + s
		
print sum


end_time= time()
elapse_time= end_time - start_time
print '----------'
print elapse_time, 'seconds have passed'