Esempio n. 1
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();
        }
Esempio n. 2
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);
        }
Esempio n. 3
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()));
        }