public int Run(int maxNumber) { ESieve eSieve = new ESieve(maxNumber); int[] primes = eSieve.GetPrimes().ToArray(); long[] primeSum = CalculateSums(primes).ToArray(); int maxLength = -1; int desiredPrime = -1; int i = 0; while (i < primeSum.Length) { for (int j = i - (maxLength + 1); j >= 0; --j) { if (primeSum[i] - primeSum[j] > maxNumber) { break; } int sugestedPrime = (int)(primeSum[i] - primeSum[j]); if (Array.BinarySearch(primes, sugestedPrime) > -1) { maxLength = i - j; desiredPrime = sugestedPrime; } } i++; } return(desiredPrime); }
private int GetDenominatorOfFractionsProduct() { int numeratorProduct = 1; int denominatorProduct = 1; for (int i = 10; i <= 98; ++i) { for (int j = i + 1; j <= 99; ++j) { if (IsNonTrivialExample(i, j)) { numeratorProduct *= i; denominatorProduct *= j; } } } if (denominatorProduct % numeratorProduct == 0) { return(denominatorProduct / numeratorProduct); } ESieve sieve = new ESieve((int)Math.Max(numeratorProduct, denominatorProduct)); PrimeDivisors numPrimeDivisors = new PrimeDivisors(numeratorProduct, sieve); PrimeDivisors denPrimeDivisors = new PrimeDivisors(denominatorProduct, sieve); int gcp = numPrimeDivisors.GetGCP(numPrimeDivisors); return(denominatorProduct / gcp); }
public int Run(int maxA, int maxB) { ESieve sieve = new ESieve(87400); int maxN = -1, coeffProduct = -1; for (int a = -1000; a <= maxA; ++a) { for (int b = -1000; b <= maxB; ++b) { int n = 0; while (sieve.IsPrime(n * n + a * n + b)) { n++; } if (n > maxN) { maxN = n; coeffProduct = a * b; } } } return(coeffProduct); }
public long Run(int maxValue) { ESieve sieve = new ESieve(maxValue); return(sieve.Aggregate((total, prime) => total + prime)); }
public Task35(int maxValue) { sieve = new ESieve(maxValue); }