fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. static void Main()
  8. {
  9. var sum = 0L;
  10. for (int i = 1; i <= 10000; i++)
  11. {
  12. long tmp;
  13. if ((tmp = GetDivisorSum(i)) > i && GetDivisorSum(tmp) == i)
  14. {
  15. sum += tmp + i;
  16. }
  17. }
  18. Console.WriteLine(sum);
  19. }
  20.  
  21. static long GetDivisorSum(long value)
  22. {
  23. var prime = new List<int>();
  24. var devisor = 2;
  25. var given = value;
  26. if (value <= 0)
  27. return 0;
  28. if (value == 1)
  29. return 1;
  30. while (value != 1)
  31. {
  32. if (value % devisor == 0)
  33. {
  34. prime.Add(devisor);
  35. value /= devisor;
  36. }
  37. else
  38. devisor++;
  39. }
  40. return prime.GroupBy(x => x)
  41. .Select(x => ((long)Math.Pow(x.Key, x.Count() + 1) - 1) / (x.Key - 1))
  42. .Aggregate((x, y) => x * y) - given;
  43. }
  44. }
Success #stdin #stdout 0.58s 34208KB
stdin
Standard input is empty
stdout
31626