using System; using System.Collections.Generic; using System.Linq; public class Test { static void Main() { var sum = 0L; for (int i = 1; i <= 10000; i++) { long tmp; if ((tmp = GetDivisorSum(i)) > i && GetDivisorSum(tmp) == i) { sum += tmp + i; } } Console.WriteLine(sum); } static long GetDivisorSum(long value) { var prime = new List(); var devisor = 2; var given = value; if (value <= 0) return 0; if (value == 1) return 1; while (value != 1) { if (value % devisor == 0) { prime.Add(devisor); value /= devisor; } else devisor++; } return prime.GroupBy(x => x) .Select(x => ((long)Math.Pow(x.Key, x.Count() + 1) - 1) / (x.Key - 1)) .Aggregate((x, y) => x * y) - given; } }