Ejemplo n.º 1
0
        static long S(int digitLength, int targetNum)
        {
            int m = M(digitLength, targetNum);

            int[] digitsIndex = new int[digitLength];
            for (int i = 0; i < digitLength; i++)
            {
                digitsIndex[i] = i;
            }
            List <int[]> digitsGroup = CombinationProvider.BuildDistinctCombination <int>(digitsIndex, m);
            long         s           = 0;
            int          primeCount  = 0;

            foreach (int[] digits in digitsGroup)
            {
                // 逐个创建对应的数字,如果数字为素数,则返回对应的i;
                if (digits.Contains(0) && 0 == targetNum)
                {
                    continue;
                }
                NumberGenerator ng  = new NumberGenerator(digitLength, digits, targetNum);
                long            num = ng.NextNumber();
                while (num != -1)
                {
                    if (MillerRabinCheck.isPseudoPrime(num))
                    {
                        s += num;
                        primeCount++;
                    }
                    num = ng.NextNumber();
                }
            }
            return(s);
        }
Ejemplo n.º 2
0
 static int M(int digitLength, int targetNum)
 {
     int[] digitsIndex = new int[digitLength];
     for (int i = 0; i < digitLength; i++)
     {
         digitsIndex[i] = i;
     }
     for (int currLen = digitLength - 1; currLen > 0; currLen--)
     {
         List <int[]> digitsGroup = CombinationProvider.BuildDistinctCombination <int>(digitsIndex, currLen);
         foreach (int[] digits in digitsGroup)
         {
             // 逐个创建对应的数字,如果数字为素数,则返回对应的i;
             if (digits.Contains(0) && 0 == targetNum)
             {
                 continue;
             }
             NumberGenerator ng  = new NumberGenerator(digitLength, digits, targetNum);
             long            num = ng.NextNumber();
             while (num != -1)
             {
                 if (MillerRabinCheck.isPseudoPrime(num))
                 {
                     return(currLen);
                 }
                 num = ng.NextNumber();
             }
         }
     }
     ;
     return(0);
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            BuildAllPerfectSquare();
            long product = 1;
            long i       = 1;

            while (product < 64000000)
            {
                i++;
                if (!MillerRabinCheck.isPseudoPrime(i))
                {
                    continue;
                }
                product *= i;
                primes.Add(i);
            }
        }
Ejemplo n.º 4
0
            private void DoCalculate(object param)
            {
                long      tn    = 0;
                long      count = 0;
                Stopwatch sw    = new Stopwatch();

                sw.Start();
                for (long n = this.EndNumber; n >= this.StartNumber; n--)
                {
                    tn = 2 * n * n - 1;
                    if (MillerRabinCheck.isPseudoPrime(tn))
                    {
                        count++;
                    }
                }
                if (this.SuccessHandler != null)
                {
                    this.SuccessHandler(count);
                }
            }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            long limit  = 150000000;
            long result = 0;

            for (long i = 10; i <= limit; i += 10)
            {
                long squared = i * i;

                if (squared % 3 != 1)
                {
                    continue;
                }
                if (squared % 7 != 2 && squared % 7 != 3)
                {
                    continue;
                }

                if (squared % 9 == 0 ||
                    squared % 13 == 0 ||
                    squared % 27 == 0)
                {
                    continue;
                }

                if (MillerRabinCheck.isPseudoPrime(squared + 1) &&
                    MillerRabinCheck.isPseudoPrime(squared + 3) &&
                    MillerRabinCheck.isPseudoPrime(squared + 7) &&
                    MillerRabinCheck.isPseudoPrime(squared + 9) &&
                    MillerRabinCheck.isPseudoPrime(squared + 13) &&
                    MillerRabinCheck.isPseudoPrime(squared + 27) &&
                    !MillerRabinCheck.isPseudoPrime(squared + 19) &&
                    !MillerRabinCheck.isPseudoPrime(squared + 21))
                {
                    result += i;
                }
            }
            Console.WriteLine("Result is {0}", result);
        }