public void Solve() { uint primeToCheck = Primes[Primes.Count - 1] + 2; while (!Quit) { if (CheckPrime(primeToCheck)) //number is prime { Primes.Add(primeToCheck); #region Printing Stats if ((Primes.Count - 1) % 10_000 == 0) { OnTenThousandthPrime(primeToCheck, (uint)(Primes.Count - 1)); } if ((Primes.Count - 1) % 100_000 == 0) { OnHundredThousandthPrime(primeToCheck, (uint)(Primes.Count - 1)); } if ((Primes.Count - 1) % 1000000 == 0) { OnMillionthPrime(primeToCheck, (uint)(Primes.Count - 1)); } #endregion Printing Stats } primeToCheck = primeToCheck + 2; //set next prime } }
private void ExtendPrimes() { Int64 limit = (Int64)(Math.Floor(Math.Sqrt(Composite))); var last = Primes.Last() + 2; while (last <= limit) { if (IsPrime(last)) { Primes.Add(last); } last += 2; } }
private void SolvePrimes() { uint lower = LowerBound; uint upper = UpperBound; for (uint i = lower; i < upper; i++) { if (CheckPrime(i)) { Primes.Add(i); } } OnPrimesFound(); }
private void generator() { bool[] composite = new bool[Max + 1]; for (int i = 2; i *i <= Max; i++) { for (int j = i; i *j <= Max; j++) { composite[i * j] = true; } } for (int i = Min; i <= Max; i++) { if (!composite[i]) { Primes.Add(i); } } }
public long NextPrime() { long currentCandidate = Primes.Last().Model.Value + 1; while (currentCandidate < long.MaxValue) { long startTicks = _stopwatch.ElapsedTicks; if (SelectedGenerationStrategy.Model.ValidatePrime(currentCandidate)) { long elapsed = _stopwatch.ElapsedTicks - startTicks; Primes.Add(new PrimeViewModel(Primes.Last().Model.Id + 1, currentCandidate, new TimeSpan(elapsed))); return(currentCandidate); } else { currentCandidate++; } } throw new OverflowException($"No prime numbers exist found between {currentCandidate} and {long.MaxValue}."); }
private void PrepPrimes() { for (int i = 2; i < field; i++) { bool found = false; foreach (var prime in Primes) { if ((i % prime) == 0) { found = true; break; } } if (!found) { Primes.Add(i); found = false; } } Offset += field; }