예제 #1
0
 private static IEnumerable <long> GetFactors(this long x) =>
 StrangeEnumerable.Range(1, x.GetCeiling())
 .Where(n => x.IsEvenlyDivisibleBy(n))
 .SelectMany(n =>
             n != x / n
         ? new[] { n, x / n }
         : new[] { n });
예제 #2
0
 public static IEnumerable <long> GetPrimeFactors(this long x) =>
 StrangeEnumerable.Range(2, x.GetCeiling())
 .Where(n => x.IsEvenlyDivisibleBy(n))
 .SelectMany(n =>
             (x / n).IsPrime()
         ? n.IsPrime()
             ? n != x / n ? new[] { n, x / n } : new[] { n }
             : new[] { x / n }
         : n.IsPrime()
             ? new[] { n }
             : new long[] { });