internal void PopulateAbundantNumberList() { u32 *List = 0; for(u32 PotentialAbundantNumber = 1; PotentialAbundantNumber < AbundantNumberLimit; ++PotentialAbundantNumber) { if(IsAbundant(PotentialAbundantNumber)) { buffer_push(List, PotentialAbundantNumber); } } AbundantNumberList.List = List; AbundantNumberList.Length = buffer_count(List); }
int _tmain(int argc, _TCHAR* argv[]) { const int max = 28123; std::vector<int> abudantNumbers; std::set<int> result; for (int i = 2; i <= max; ++i) { if (IsAbundant(i)) { abudantNumbers.push_back(i); } } std::set<int>::size_type numberOfAbundantNumbers = abudantNumbers.size(); for (int i = 2; i <= max; ++i) { if ((i % 2 == 0) && IsAbundant(i / 2)) { //std::cout << i << " = " << i / 2 << " + " << i / 2 << std::endl; continue; } else { result.insert(i); for (std::set<int>::size_type j = 0; j < abudantNumbers.size(); ++j) { int first = abudantNumbers[j]; int second = i - first; if (second < abudantNumbers[0]) { // concluded: CANNOT be expressed as sum of two abudant numbers break; } if (second <= abudantNumbers[numberOfAbundantNumbers - 1]) { if (std::find(abudantNumbers.begin(), abudantNumbers.end(), second) != abudantNumbers.end()) { // concluded: CAN be expressed as sum of two abudant numbers //std::cout << i << " = " << first << " + " << second << std::endl; result.erase(i); break; } } } } } int sum = 0; for (const auto& element : result) sum += element; std::cout << sum << std::endl; return 0; }