public static int ProductOfCoefficientOfQuadraticFormulaProducingMorePrimeNumbers() { var maxPrimeNumbers = int.MinValue; int aValue = int.MinValue; int bValue = int.MinValue; var primesUntil999 = PrimeNumbers.PrimesUntilN(999); for (int a = -999; a < 1000; a++) { for (int b = 2; b <= 999; b++) { if (primesUntil999[b]) { int n; for (n = 1; PrimeNumbers.IsPrimeNumber(n * n + a * n + b); n++) { ; } if (n > maxPrimeNumbers) { maxPrimeNumbers = n; aValue = a; bValue = b; } } } } return(aValue * bValue); }
public static long SumPrimesBelowN(int num) { var primes = PrimeNumbers.PrimesUntilN(num - 1); long sum = 2; for (int i = 3; i < primes.Length; i += 2) { if (primes[i]) { sum += i; } } return(sum); }
public static int ConsecutivePrimeSum(int num) { var primes = PrimeNumbers.PrimesUntilN(num); int greatestPrimeSum = 0; int largestStreak = 0; for (int i = 0; i < primes.Length; i++) { if (primes[i]) { int currentStreak = 0; int currentSum = 0; for (int j = i; j < primes.Length; j++) { if (primes[j]) { currentSum += j; if (currentSum >= num) { break; } currentStreak++; if (primes[currentSum] && currentStreak > largestStreak) { largestStreak = currentStreak; greatestPrimeSum = currentSum; } } } } } return(greatestPrimeSum); }
public E035_Circular_primes(int threshold) { _threshold = threshold; _primeNumbers = PrimeNumbers.PrimesUntilN(_threshold - 1); }