public override void Process() { PrimeGenerator primeGenerator = new PrimeGenerator(); int upperLimit = 1000000, chainLength = 0, maxPrime = 0; List<int> primes = primeGenerator.Below(upperLimit); long[] consecutiveSum = GenerateConsecutiveSum(primes); for (int j = chainLength; j < consecutiveSum.Count(); j++) { for (int k = j - (chainLength + 1); k >= 0; k--) { int checkPrime = (int)(consecutiveSum[j] - consecutiveSum[k]); if (checkPrime > upperLimit) break; if (!primeGenerator.IsPrime(checkPrime)) continue; chainLength = j - k; maxPrime = checkPrime; } } Console.WriteLine("Prime: {0} made from a chain of {1} consecutive primes", maxPrime, chainLength); }
public override void Process() { int upperLimit = 10000; PrimeGenerator generator = new PrimeGenerator(); List<int> primes = generator.Between(1000, upperLimit); for (int i = 0; i < primes.Count(); i++) { int a = primes[i]; for (int j = i + 1; j < primes.Count(); j++) { int b = primes[j]; int c = b + (b - a); if (c > upperLimit) break; if (generator.IsPrime(c) && ArePermutable(a, b, c)) { Console.WriteLine("{0}{1}{2} (Step: {3})", a, b, c, c - b); } } } }