Project Euler 23: Non Abundant Sums Here is my solution to Project Euler 23: Non Abundant Sums. I know I'm doing the Divisors function brute force, but I can't seem to get it to work any other way. Any improvements are welcome.

#include &lt;iostream&gt;
#include &lt;vector&gt;

//Calculates divisors
void Divisors(unsigned number, std::vector&lt;unsigned&gt; &amp;result){
    for(unsigned a = 1; a &lt; number; a++){
        if(number % a == 0){
            result.push_back(a);
        }
    }
}
//Calls for divisors and adds them
unsigned SumOfDivisors(unsigned number){
    unsigned result = 0;
    std::vector&lt;unsigned&gt; divisors;
    Divisors(number, divisors);
    for(unsigned a = 0; a &lt; divisors.size(); a++){
        if(divisors[a] &lt; number)
            result += divisors[a];
    }
    return result;
}
//Calls calculates the sum of divisors to see if it is Abundant
bool IsAbundant(unsigned number){
    if(SumOfDivisors(number)&gt; number){
        return true;
    }
    else{
        return false;
    }
}
//pushes back abundant numbers
void Abundant(unsigned limit, std::vector&lt;unsigned&gt; &amp;abunNumbers){
    for(unsigned a = 1; a &lt; limit; a++){
        if(IsAbundant(a)){
            abunNumbers.push_back(a);
        }
    }
}

//Find's all number's that are the sum of two abundant numbers
void SumOfAbundant(unsigned limit, std::vector&lt;unsigned&gt; const&amp; abunNumbers, std::vector&lt;bool&gt; &amp;sumAbun){
    for(unsigned a = 0; a &lt; abunNumbers.size(); a++){
        for(unsigned b = a; b &lt; abunNumbers.size(); b++){
            if(abunNumbers[a]+abunNumbers[b] &lt;= limit){
                sumAbun[abunNumbers[a]+abunNumbers[b]] = true;
            }
        else{
            break;
        }
        }
    }
}

int main(){
    const unsigned limit = 28123;
    unsigned result = 0;

    std::vector&lt;unsigned&gt;abunNumbers;
    Abundant(limit, abunNumbers);

    std::vector&lt;bool&gt;sumAbun(limit,false);
    SumOfAbundant(limit, abunNumbers, sumAbun);


    for(unsigned a = 0 ; a &lt; sumAbun.size() ; a++){
        if(!sumAbun[a]){
        result += a;
        }
    }
    std::cout &lt;&lt; result;
}
I would recommend the following changes:


Math is your friend. Factorize the number into prime powers (a precalculated table of primes is of immence value for a lot of Project Euler problems), and use a formula from this article.
Memoize. As soon as you identify a single (prime) divisor of a number, and take the quotient, notice that the quotient was already inspected and factorized. A vector of tuples (prime, power) representing a factorization may also help a lot.


There could be other optimizations, but these two seem to be enough.