title: Optimize non-abundant sums algorithm
body: <p>I am trying to solve <a href="http://projecteuler.net/index.php?section=problems&amp;id=23" rel="nofollow">this Project Euler question</a>:</p>
  
  <blockquote>
    <p>A perfect number is a number for which the sum of its proper divisors
    is exactly equal to the number. For example, the sum of the proper
    divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28
    is a perfect number.</p>
    
    <p>A number n is called deficient if the sum of its proper divisors is
    less than n and it is called abundant if this sum exceeds n.</p>
    
    <p>As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the
    smallest number that can be written as the sum of two abundant numbers
    is 24. By mathematical analysis, it can be shown that all integers
    greater than 28123 can be written as the sum of two abundant numbers.
    However, this upper limit cannot be reduced any further by analysis
    even though it is known that the greatest number that cannot be
    expressed as the sum of two abundant numbers is less than this limit.</p>
    
    <p>Find the sum of all the positive integers which cannot be written as
    the sum of two abundant numbers.</p>
  </blockquote>
  
  <p>My solution:</p>
  
  <pre><code>#returns a list of the divisors of a given number
  def Divs(Number):
      Divisors = []
  
      for i in range(2 , int(Number**0.5) + 1):
          if Number % i == 0:
              Divisors.append(i)
  
      for q in range(len(Divisors)):
          if Divisors[q] != (Number / Divisors[q]):
              Divisors.append(Number / Divisors[q])
  
      Divisors.insert(0,1)
      return Divisors
  
  #returns a list of abundant numbers up to and including the limit
  def AbList(limit):
      Abundant = []
  
      for i in range(11,limit + 1):
          if sum(Divs(i)) &gt; i:
              Abundant.append(i)
  
      return Abundant
  
  #Finds the sum of all positive integers that cannot be written as the
  #sum of two abundant numbers...
  def AbSum(limit):
      Abundant = AbList(limit)
      NoAbSum = 0
      for i in range(1 , limit):
          AbSum = 0
          x = 0
          for x in Abundant:
              if i - x in Abundant[:i]:
                  AbSum = 1
                  break
          if AbSum == 0:
              NoAbSum += i
      return NoAbSum
  </code></pre>
  
  <p>This took my 3.4 GhZ processor about 15 minutes to solve and I am searching for a better way. I'm not concerned with the first two functions because together they take less than a second to run. The third function is the kicker here. It runs through the range of numbers up to the limit (in this case, 20000-something), and each time, it runs through the list of abundant numbers, subtracting each from the current number, then checking that answer against the list of abundant numbers. If there is a match, the loop breaks and tries again with the next number, all the way up to the limit.</p>
  
  <p>I know there has got to be a better way of doing this but I'm somewhat new to programming. How can I speed up this algorithm?</p>