static void Main(string[] args) { List<AmicablePair> pairs = new List<AmicablePair>(); var a = new AmicableCalculator(); for (int i = 1; i < 10000; i++) { var sumOfDivisors = a.GetDivisorsSum(i); if (a.IsAmicable(i, sumOfDivisors)) { pairs.Add(new AmicablePair() { FirstNumber = i, SecondNumber = sumOfDivisors }); } } pairs = pairs.Where(elm => elm.FirstNumber != elm.SecondNumber).ToList(); var sum = 0; foreach (var pair in pairs) { sum += pair.FirstNumber; sum += pair.SecondNumber; } Console.WriteLine(sum / 2); Console.ReadLine(); }
public void IsNotAmicable() { AmicableCalculator a = new AmicableCalculator(); var result = a.IsAmicable(221, 284); Assert.IsFalse(result); }
public void IsAmicable() { AmicableCalculator a = new AmicableCalculator(); var result = a.IsAmicable(220, 284); Assert.IsTrue(result); }
public void GetDivisorsSum() { AmicableCalculator a = new AmicableCalculator(); var result = a.GetDivisorsSum(220); Assert.AreEqual(284, result); }
public void GetDivisors() { AmicableCalculator a = new AmicableCalculator(); var result = a.GetDivisiorsOfNumber(220); Assert.AreEqual(11, result.Count); }