public void FactorUtils_GetFactors_28() { AssertEqual(new long[] { 1, 2, 4, 7, 14, 28 }, FactorUtils.GetFactors((long)28)); }
public void FactorUtils_GetFactors_2() { AssertEqual(new long[] { 1, 2 }, FactorUtils.GetFactors((long)2)); }
public void FactorUtils_GetFactors_10() { AssertEqual(new long[] { 1, 2, 5, 10 }, FactorUtils.GetFactors((long)10)); }
private static Dictionary <int, int> GetFactorSumDict(int n) { return(Enumerable.Range(2, n - 2) .Select(i => new { i, FactorSum = (int)FactorUtils.GetProperFactors(i).Sum() }) .ToDictionary(a => a.i, a => a.FactorSum)); }
public void FactorUtils_GetFactors_1() { AssertEqual(new long[] { 1 }, FactorUtils.GetFactors((long)1)); }
public static bool IsAbundant(this int n) { return(FactorUtils.GetProperFactors(n).Sum() > n); }
public static bool IsPerfect(this int n) { return(FactorUtils.GetProperFactors(n).Sum() == n); }
public static bool IsDeficient(this int n) { return(FactorUtils.GetProperFactors(n).Sum() < n); }
public static long AmicableSumUnderN(int n) { var factorSumDict = Enumerable.Range(2, n - 2).Select(i => new { i, FactorSum = (int)FactorUtils.GetProperFactors(i).Sum() }) .Where(p => p.FactorSum > 1).ToDictionary(a => a.i, a => a.FactorSum); var amicableNumbers = factorSumDict .Where(d => factorSumDict.ContainsKey(d.Value) && d.Key == factorSumDict[d.Value] && d.Key != d.Value) .SelectMany(i => new[] { i.Key, i.Value }).Distinct().ToList(); return(amicableNumbers.Sum()); }
public static long TriangleNumberWithNDivisors(int n) { return(TriangleNumberUtils.TriangleNumbers.SkipWhile(t => FactorUtils.GetFactors(t).Count() < n).First()); }