private void FindWays() { for (int ii = 2; ii <= Value / 2 + 1; ii++) { if (Value % ii == 0) { Divisors.Add(ii); } var fraction = Value / ii; var smallestStart = Math.Max(1, fraction - ii - 1); for (var start = smallestStart; start <= ii; start++) { if (Ways.Any(existingWay => existingWay.First() == start)) { continue; } var way = new List <int>(); var sum = 0; var num = start; while (sum < Value) { sum += num; way.Add(num); num++; } if (sum == Value) { Ways.Add(way); } } } }
public void AddDivisor(long number) { if (number <= 0) { throw new ArgumentOutOfRangeException(nameof(number), $"The number {number} is not a valid Divisor."); } Divisors.Add(number); }