Пример #1
0
        public Primer FindPrime(Primer p)
        {
            bool isPrime = false;
               uint primeCandidate = p.StartNumber;

               do
               {
               primeCandidate += 1;

               if (primeCandidate % 2 != 0)
               {
                   uint primeDetector = 0;

                   for (uint i = 3; i <= Math.Sqrt(primeCandidate); i += 2)
                   {
                       if (primeCandidate % i == 0)
                       {
                           primeDetector++;
                       }
                   }

                   if (primeDetector == 0)
                       isPrime = true;

               }

               } while (isPrime == false);
               p.PrimeNumber = primeCandidate;
               return p;
        }
Пример #2
0
 public ActionResult NextPrime(PrimeSearchTool number)
 {
     if (ModelState.IsValid)
     {
         var primeFinder = new PrimeFinder();
         var primer = new Primer();
         primer.StartNumber = number.FirstNumber.Value;
         primer = primeFinder.FindPrime(primer);
         number.NextPrime = primer.PrimeNumber;
         return View("NextPrime", number);
     }
     return View("NextPrime", number);
 }