コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        private static long SumPrimesBelowLimit(int limit)
        {
            IEnumerable <long> primes = PrimesUtility.GeneratePrimesBelowUpperLimit(limit);

            return(primes.Sum());
        }
コード例 #4
0
ファイル: PrimeTests.cs プロジェクト: reashore/Problems
        public void SetUp()
        {
            const int upperBound = 700_000;

            _primesUtility = new(upperBound);
        }