Exemple #1
0
        //The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

        //Find the sum of all the primes below two million.
        public static long Execute()
        {
            const int max = 2000000;

            long sum = 0;

            for (var i = 2; i < max; i++)
            {
                if (PrimeHelper.IsPrimeWithHistory(i))
                {
                    sum += i;
                }
            }

            return(sum);
        }
Exemple #2
0
        //By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

        //What is the 10001st prime number?
        /// <summary>
        /// 500000 gives 7368787 and takes 5 seconds
        /// </summary>
        public static int Execute()
        {
            var maxPrimeCount = 10001;

            // Skip first 3 primes
            var primeCount = 3;
            var i          = 3;

            while (primeCount <= maxPrimeCount)
            {
                i = i + 2;
                if (PrimeHelper.IsPrimeWithHistory(i))
                {
                    primeCount++;
                }
            }

            return(i);
        }