Esempio n. 1
0
        static void Main(string[] args)
        {
            int   num        = 1;
            int   len        = 1;
            int   primecount = 0;
            float ratio      = 0f;
            int   step       = 0;

            while (true)
            {
                len        += 2;
                step        = len - 1;
                num         = num + step;
                primecount += pg.CheckPrime(num)?1:0;
                num         = num + step;
                primecount += pg.CheckPrime(num) ? 1 : 0;
                num         = num + step;
                primecount += pg.CheckPrime(num) ? 1 : 0;
                num         = num + step;
                primecount += pg.CheckPrime(num) ? 1 : 0;
                ratio       = (float)primecount / (float)(len * 2 - 1);
                Console.WriteLine("len:\t{0},primecount:\t{1},totalcount\t{2},ratio:\t{3}", len, primecount, len * 2 - 1, ratio);
                if (primecount * 10 < len * 2 - 1)
                {
                    Console.Out.WriteLine(string.Format("result is {0}", len));
                    break;
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            PrimeGenerator pg          = new PrimeGenerator();
            double         target      = 15499d / 94744d;
            double         totient     = 1d;
            double         denominator = 1d;
            long           answer      = 0;

            for (int p = 2; ;)
            {
                totient     *= p - 1;
                denominator *= p;
                do
                {
                    p++;
                }while (!pg.CheckPrime(p));

                if (totient / denominator < target)
                {
                    for (int j = 1; j < p; j++)
                    {
                        if ((j * totient) / (j * denominator - 1) < target)
                        {
                            answer = j * (long)denominator;
                            Console.WriteLine("Result is {0}", answer);
                            return;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     primes = new List<int>();
     for (int i = 1000; i <= 9999; i++)
     {
         if (pg.CheckPrime(i,false))
             primes.Add(i);
     }
     
     List<string> result = new List<string>();
     foreach (int prime in primes)
     {
         if (prime == 2969)
         {
             Console.WriteLine();
         }
         int[] nums = BuildSeqNumbers(prime,true);
         if (nums.Count() < 3)
             continue;
         List<int[]> tripleGroup = PermutationProvider.BuildPermutation<int>(nums, 3);
         foreach (int[] triple in tripleGroup)
         {
             int[] temptpl = triple.OrderBy(x => x).ToArray();
             if ((temptpl[2] - temptpl[1]) != (temptpl[1] - temptpl[0]))
                 continue;
             string item = string.Format("{0}{1}{2}", temptpl[0], temptpl[1], temptpl[2]);
             if (result.Contains(item))
                 continue;
             result.Add(item);
         }
     }
 }
Esempio n. 4
0
 public void CheckPrimeTest()
 {
     PrimeGenerator target = new PrimeGenerator(); // TODO: 初始化为适当的值
     int number = 0; // TODO: 初始化为适当的值
     bool expected = false; // TODO: 初始化为适当的值
     bool actual;
     for (int i = 3; i <= int.MaxValue; i+=2)
     {
         if (target.CheckPrime(i))
         {
             Console.Write(i + " , ");
         }
     }
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            PrimeGenerator target = new PrimeGenerator();
            int            i      = 3;
            int            index  = 1;

            while (true)
            {
                if (target.CheckPrime(i))
                {
                    index++;
                }
                if (index == 10001)
                {
                    Console.WriteLine(i);
                    break;
                }
                i += 2;
            }
            Console.ReadLine();
        }
Esempio n. 6
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()));
        }