private static long Run(int limit) { IList <int> primes = PrimesUtility.GeneratePrimesBelowUpperLimit(limit).Select(a => (int)a).ToList(); IList <int> resultNumbers = new List <int>(); IList <int> notPrimesFiltered = Enumerable.Range(2, limit - 1).ToList(); int primesCount = primes.Count; for (int i = 0; i < primesCount; i++) { int prime = primes[i]; while (notPrimesFiltered.Any(q => q % prime == 0)) { resultNumbers.Add(prime); notPrimesFiltered = FilterOutNumbers(notPrimesFiltered, prime); } if (!notPrimesFiltered.Any()) { break; } } long result = 1; foreach (int prime in resultNumbers) { result *= prime; } return(result); }
static void Main() { List <int> primeMax = new List <int>(); double totalMiliSeconds = Euler.Common.MeasureTool.MeasureTotalMiliSeconds(() => { primeMax = PrimesUtility.GenerateSpecificNumberOfPrimes(limit); }); Console.WriteLine("10 001st prime: " + primeMax.Last() + ". Calculated in " + totalMiliSeconds + " ms"); Console.Read(); }
private static long SumPrimesBelowLimit(int limit) { IEnumerable <long> primes = PrimesUtility.GeneratePrimesBelowUpperLimit(limit); return(primes.Sum()); }
public void SetUp() { const int upperBound = 700_000; _primesUtility = new(upperBound); }