public string GetSolution() { var totalSum = 0; for (int i = 2; i < 10000; i++) { var divisorsSum = Factors.GetProperDivisors(i).Sum(); var otherDivisorsSum = Factors.GetProperDivisors(divisorsSum).Sum(); if (i != divisorsSum && otherDivisorsSum < 10000 && otherDivisorsSum == i) { totalSum += i; } } return(totalSum.ToString()); }
public string GetSolution() { var abundantNumbers = Enumerable.Range(1, limit).Where(n => Factors.GetProperDivisors(n).Sum() > n).ToArray(); var abundantSums = new Dictionary <int, bool>(); for (int i = 0; i < abundantNumbers.Length; i++) { for (int j = i; j < abundantNumbers.Length; j++) { var sum = abundantNumbers[i] + abundantNumbers[j]; if (sum > limit) { break; } abundantSums[sum] = true; } } return(Enumerable.Range(1, limit).Except(abundantSums.Keys).Sum().ToString()); }