you would generate the dictionary something like thisMy solution to your problem:
def GetSumOfDivs(n):
i = 2
upper = n
total = 1
while i < upper:
if n%i == 0:
upper = n/i
total += upper
if upper != i: total += i
i += 1
return total
def isabundant(n): return GetSumOfDivs(n) > n
abundantslAbundants = {x:0[x for x in range(12, 28123) if isabundant(x) == TrueTrue]
dAbundants = {x:x for x in lAbundants}
sums = 1
for i in range(2, 28123):
boo = True
for k in lAbundants:
if k < i:
if (i-k) in dAbundants:
boo = False
break
else : break
if boo == True: sums += i
print(sums)
Why a list and a dictionary? the list is ordered and the dictionary for fast indexing.
Total execution time: 12.08 seconds
now try it in C++... I'm sure its under 2 seconds... XD good luck