Пример #1
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;
                        }
                    }
                }
            }
        }
Пример #2
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()));
 }
Пример #3
0
 static void Main(string[] args)
 {
     nums = new int[Max + 1][];
     for (int i = 0; i <= Max; i++)
     {
         nums[i] = new int[] { i, 1, i };
     }
     int[] primes = new PrimeGenerator().GetPrimesBelowOneMillion();
     for (int i = 0; i <= primes.Length; i++)
     {
         int prime = primes[i];
         if (prime > Max)
             break;
         int start = prime;
         while (start <= Max)
         {
             nums[start][1] *= prime;
             while (nums[start][0] % prime == 0)
             {
                 nums[start][0] = nums[start][0] / prime;
             }
             start += prime;
         }
     }
     var ordered = nums.OrderBy(x => x[1]);
     int result = ordered.Skip(10000).Take(1).FirstOrDefault()[2];
     Console.WriteLine("Result is {0}", result);
     Console.ReadLine();
 }
 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 + " , ");
         }
     }
 }
Пример #5
0
 static void Main(string[] args)
 {
     PrimeGenerator pg = new PrimeGenerator();
     bool[] primeArray = pg.CheckPrimeNumber(2000000);
     long sum = 0;
     for (int i = 0; i < primeArray.Length; i++)
     {
         if (primeArray[i])
         {
             sum += i;
         }
     }
     Console.WriteLine(sum);
     Console.Read();
 }
Пример #6
0
 static void Main(string[] args)
 {
     PrimeGenerator pg = new PrimeGenerator();
     int[] primes = pg.GetPrimesBelowOneMillion();
     int rlt = 1;
     int tmp = 1;
     foreach(int p in primes){
         tmp = tmp * p;
          if (tmp >= NUMCOUNT)
          {
              break;
          }
          rlt = tmp;
     }
     Console.WriteLine(rlt);
 }
Пример #7
0
 static void Main(string[] args)
 {
     PrimeGenerator pg = new PrimeGenerator();
     int[] primes = pg.GetPrimesBelowOneMillion();
     bool[] primeMark = pg.CheckPrimeNumber(1000000);
     for (int i = 0; i < primes.Length; i++)
     {
         int prime = primes[i];
         int[] digits = NumberUtils.SplitNumber(prime,1);
         for (int mark = 1; mark < ((1 << digits.Length) -  1); mark++)
         {
             int primeCount = 0;
             for (int n = 0; n < 10; n++)
             {
                 int[] markedDigits = ChangeMarkedDigits(digits, mark, n);
                 if (markedDigits[0] % 2 == 0 || markedDigits[0] % 5 == 0)
                     continue;
                 if (markedDigits[digits.Length - 1] == 0)
                     continue;
                 int num = MarkDigitsToNumber(markedDigits);
                 if (!primeMark[num])
                     continue;
                 primeCount++;
             }
             if (primeCount == 8)
             {
                 int result = int.MaxValue;
                 for (int n = 0; n < 10; n++)
                 {
                     int[] markedDigits = ChangeMarkedDigits(digits, mark, n);
                     if (markedDigits[0] % 2 == 0 || markedDigits[0] % 5 == 0)
                         continue;
                     if (markedDigits[digits.Length - 1] == 0)
                         continue;
                     int num = MarkDigitsToNumber(markedDigits);
                     if (!primeMark[num])
                         continue;
                     if (num < result)
                         result = num;
                 }
                 Console.WriteLine("Result is {0}", result);
                 return;
             }
             //Console.WriteLine(Convert.ToString(mark, 2));
         }
     }
 }
Пример #8
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();
 }
Пример #9
0
 static void GetPrimeMark()
 {
     primes = new bool[MAX_PRIME + 1];
     for (int i = 0; i < MAX_PRIME + 1; i++)
     {
         primes[i] = true;
     }
     PrimeGenerator pg = new PrimeGenerator();
     int sqrt = (int)Math.Sqrt(MAX_PRIME);
     primes[0] = false;
     primes[1] = false;
     for (int i = 2; i < sqrt; i++)
     {
         int tempPos = i * 2;
         while (tempPos < MAX_PRIME)
         {
             primes[tempPos] = false;
             tempPos += i;
         }
     }
 }
Пример #10
0
 static void Main(string[] args)
 {
     for (int i = 0; i < 10000; i++)
     {
         squares[i * i] = true;
     }
     squares[0] = false;
     PrimeGenerator pg = new PrimeGenerator();
     primes = pg.GetPrimesBelowOneMillion();
     primeTag = pg.CheckPrimeNumber(1000000);
     int squTwice = 0;
     int firstOdd = 0;
     bool pass = false;
     for (int i = 3; ; i += 2)
     {
         if (primeTag[i])
             continue;
         pass = false;
         foreach (int prime in primes)
         {
             if (i <= prime)
                 break;
             squTwice = i - prime;
             if (squTwice % 2 != 0)
                 continue;
             squTwice = squTwice / 2;
             if (!squares[squTwice])
                 continue;
             pass = true;
             break;
         }
         if (pass)
             continue;
         firstOdd = i;
         break;
     }
     Console.WriteLine(string.Format("Result is {0}", firstOdd));
 }
Пример #11
0
 //static int MAX = 50;
 static void Main(string[] args)
 {
     int[] primes = new PrimeGenerator().GetPrimesBelowOneMillion();
     int resultCount = 0;
     int d = 0;
     int t = 0;
     int s = 0;
     List<int> result = new List<int>();
     while (true)
     {
         int sp = primes[s];
         int sr = (int)Math.Pow(sp, 4);
         if (sr >= MAX)
             break;
         t = 0;
         while (true)
         {
             int tp = primes[t];
             int tr = (int)Math.Pow(tp, 3);
             if (sr + tr >= MAX)
                 break;
             d = 0;
             while (true)
             {
                 int dp = primes[d];
                 int dr = (int)Math.Pow(dp, 2);
                 if (sr + tr + dr >= MAX)
                     break;
                 d++;
                 result.Add(sr + tr + dr);
             }
             t++;
         }
         s++;
     }
     resultCount = result.Distinct().Count();
     Console.WriteLine("Result is {0}", resultCount);
 }