示例#1
0
        static void Main(string[] args)
        {
            TriangleNumberGenerator tng = new TriangleNumberGenerator();
            FactorsGenerator        fg  = new FactorsGenerator();
            int maxDivisorCount         = 0;

            while (true)
            {
                int factors = fg.GeneratorDistinctDivisorCount(tng.Next());
                if (factors > maxDivisorCount)
                {
                    maxDivisorCount = factors;
                }
                Console.Out.WriteLine(string.Format("number:{0} - count:{1} - maxcount: {2}", tng.CurrentTriangle, factors, maxDivisorCount));
                if (factors <= 500)
                {
                    continue;
                }
                Debug.Write(tng.CurrentTriangle + "\r\n");
                Console.Out.Write(tng.CurrentTriangle + ":");
                Console.Write("\r\n");
                break;
            }
            Console.Read();
        }
示例#2
0
        /// <summary>
        /// 由于除数数量很少,没有逐个判断是否是prime
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            FactorsGenerator generator = new FactorsGenerator();
            List <long>      factors   = generator.GeneratorDistinctFactors(600851475143);

            foreach (long factor in factors)
            {
                Console.Write(factor + ",");
            }
            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            Dictionary <int, List <int> > c = new Dictionary <int, List <int> >();
            FactorsGenerator fg             = new FactorsGenerator();

            for (int i = 1; i < 500; i++)
            {
                int count = fg.GeneratorDistinctDivisor(i).Count;
                if (!c.ContainsKey(count))
                {
                    c.Add(count, new List <int>());
                }
                c[count].Add(i);
                continue;
            }
        }
示例#4
0
        static AbundantCheckNumber BuildAbundantCheckNumber(long value, FactorsGenerator fg)
        {
            List <long> divisors = fg.GeneratorDistinctDivisor(value);
            long        sum      = 0;

            foreach (long div in divisors)
            {
                if (div < value)
                {
                    sum += div;
                }
            }
            if (sum == value)
            {
                return new AbundantCheckNumber()
                       {
                           Value = value, NumberType = NumberType.Perfect, DivisorsSum = sum
                       }
            }
            ;

            if (sum < value)
            {
                return new AbundantCheckNumber()
                       {
                           Value = value, NumberType = NumberType.Deficient, DivisorsSum = sum
                       }
            }
            ;

            if (sum > value)
            {
                return new AbundantCheckNumber()
                       {
                           Value = value, NumberType = NumberType.Abundant, DivisorsSum = sum
                       }
            }
            ;

            return(new AbundantCheckNumber()
            {
                Value = value, NumberType = NumberType.NotChecked, DivisorsSum = sum
            });
        }
    }
}
示例#5
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            FactorsGenerator fg  = new FactorsGenerator();
            float            min = 1f / 3;
            float            max = 1f / 2;

            FactMatrix = new int[MAXNUM + 1][];
            for (int i = 0; i <= MAXNUM; i++)
            {
                FactMatrix[i] = fg.GeneratorDistinctFactors(i).ToArray();
            }
            ;
            sw.Stop();
            Console.WriteLine("init base data time used {0}m{1}s{2}ms", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);
            sw.Restart();
            int result = 0;

            for (int i = MAXNUM; i >= 2; i--)
            {
                // 计算小于此i数字所有的互质数
                for (int j = 1; j < i; j++)
                {
                    // 检查是不是互质数
                    if (!IsReltavePrime(i, j))
                    {
                        continue;
                    }
                    float val = (float)j / i;
                    if (val <= min)
                    {
                        continue;
                    }
                    if (val >= max)
                    {
                        continue;
                    }
                    result++;
                }
                // 统计在1/3 和 1/2的数字
            }
            sw.Stop();
            Console.WriteLine("result is {0}, time used {1}m{2}s{3}ms", result, sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);
        }
示例#6
0
        static List <long> findAllAbundantLessThan28123()
        {
            FactorsGenerator fg     = new FactorsGenerator();
            List <long>      result = new List <long>();

            for (int i = 1; i < MAXLENGTH; i++)
            {
                if (i == 28123)
                {
                    Console.WriteLine();
                }
                AbundantCheckNumber num = BuildAbundantCheckNumber(i, fg);
                if (num.NumberType == NumberType.Abundant)
                {
                    result.Add(i);
                }
            }
            return(result);
        }
示例#7
0
        static void Main(string[] args)
        {
            FactorsGenerator fg           = new FactorsGenerator();
            PrimeGenerator   pg           = new PrimeGenerator();
            Queue <long>     consecutives = new Queue <long>();

            for (long num = 1000; ; num++)
            {
                List <long> factors = fg.GeneratorDistinctFactors(num);
                if (factors.Count != 4)
                {
                    continue;
                }
                bool allprime = true;
                foreach (long factor in factors)
                {
                    if (pg.CheckPrime((int)factor))
                    {
                        continue;
                    }
                    allprime = false;
                    break;
                }
                if (!allprime)
                {
                    continue;
                }
                consecutives.Enqueue(num);
                if (CheckConsecutive(consecutives, 4))
                {
                    break;
                }
                if (consecutives.Count == 4)
                {
                    consecutives.Dequeue();
                }
            }
            Console.WriteLine(string.Format("Result is {0}", consecutives.Peek()));
        }