Пример #1
0
 public static IEnumerable <long> GetAbundantNumbers(long limit)
 {
     return
         (Sequences.LongRange(1, limit)
          .Select(n => new Tuple <long, HashSet <long> >(n, Problem012.GetFactors(n)))
          .Where(t => t.Item1 < t.Item2.Sum() - t.Item1)    // subtract t.Item1 to get only proper divisors
          .Select(t => t.Item1));
 }
Пример #2
0
        public string Solve()
        {
            var result = Enumerable.Range(2, 9998).Select(n =>
            {
                // may want to refactor GetFactors to return a copy...
                var factors = Problem012.GetFactors(n);
                // get n, sum of factors of n
                return(Tuple.Create((long)n, factors.Sum() - n));
            }).Where(n =>
            {
                // remove self-amicable numbers (6, 496, 8128)
                if (n.Item1 == n.Item2)
                {
                    return(false);
                }
                var factors = Problem012.GetFactors(n.Item2);
                // do the sum of the factors of (the sum of the factors of n) equal n?
                return(n.Item1 == (factors.Sum() - n.Item2));
            }).Select(n => n.Item1).Distinct();

            return(result.Sum().ToString());
        }