コード例 #1
0
 public void FactorUtils_GetFactors_28()
 {
     AssertEqual(new long[] { 1, 2, 4, 7, 14, 28 }, FactorUtils.GetFactors((long)28));
 }
コード例 #2
0
 public void FactorUtils_GetFactors_2()
 {
     AssertEqual(new long[] { 1, 2 }, FactorUtils.GetFactors((long)2));
 }
コード例 #3
0
 public void FactorUtils_GetFactors_10()
 {
     AssertEqual(new long[] { 1, 2, 5, 10 }, FactorUtils.GetFactors((long)10));
 }
コード例 #4
0
 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));
 }
コード例 #5
0
 public void FactorUtils_GetFactors_1()
 {
     AssertEqual(new long[] { 1 }, FactorUtils.GetFactors((long)1));
 }
コード例 #6
0
 public static bool IsAbundant(this int n)
 {
     return(FactorUtils.GetProperFactors(n).Sum() > n);
 }
コード例 #7
0
 public static bool IsPerfect(this int n)
 {
     return(FactorUtils.GetProperFactors(n).Sum() == n);
 }
コード例 #8
0
 public static bool IsDeficient(this int n)
 {
     return(FactorUtils.GetProperFactors(n).Sum() < n);
 }
コード例 #9
0
ファイル: V1.cs プロジェクト: wiggydave10/ProjectEuler-BHub
        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());
        }
コード例 #10
0
 public static long TriangleNumberWithNDivisors(int n)
 {
     return(TriangleNumberUtils.TriangleNumbers.SkipWhile(t => FactorUtils.GetFactors(t).Count() < n).First());
 }