======================================================================================================================== Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a != b, then a and b are an amicable pair and each of a and b are called amicable numbers. For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. Evaluate the sum of all the amicable numbers under 10000. ======================================================================================================================== """ from ProjectEuler.helper_functions import HelperFunctions as Hf d = {} for n in range(1, 10000): divisors = Hf.divisors(n) divisors.remove(n) d[n] = sum(divisors) s = 0 for n in range(1, 10000): a = n b = d[n] if b in d: a2 = d[b] if a2 == a and a != b: s += a2 + a print s/2
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the value of the first triangle number to have over five hundred divisors? ======================================================================================================================== """ from time import clock from ProjectEuler.helper_functions import HelperFunctions as Hf clock() i = 1 s = i while True: i += 1 s += i print s if Hf.number_of_divisors(s) >= 500: break print s print clock()