示例#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 bool IsPrime(this long x) =>
 x <= 1
         ? false
         : x <= 3
             ? true
             : !StrangeEnumerable.RangeTwoAndOdd(x.GetCeiling())
 .Any(n => x.IsEvenlyDivisibleBy(n));
示例#3
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[] { });