Пример #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);
        }
Пример #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);
 }