Esempio n. 1
0
        public static void Run()
        {
            DateTime start = DateTime.Now;

            int numberOfPrimes = 10001;
            var generator = new SieveOfPedro();

            int last = 0;
            for (int i = 0; i < numberOfPrimes; i++)
                last = generator.Next();

            Console.WriteLine("the {0}th prime number is {1}", numberOfPrimes, last);
            Console.WriteLine("it took {0} seconds to calcluate this", DateTime.Now.Subtract(start).TotalSeconds);
        }
Esempio n. 2
0
        public static void Run()
        {
            DateTime start = DateTime.Now;

            int numberOfPrimes = 10001;
            var generator      = new SieveOfPedro();

            int last = 0;

            for (int i = 0; i < numberOfPrimes; i++)
            {
                last = generator.Next();
            }

            Console.WriteLine("the {0}th prime number is {1}", numberOfPrimes, last);
            Console.WriteLine("it took {0} seconds to calcluate this", DateTime.Now.Subtract(start).TotalSeconds);
        }
Esempio n. 3
0
        public static void Run()
        {
            int maxPrime = 2000000;

            Stopwatch watch = Stopwatch.StartNew();

            var sieve = new SieveOfPedro();
            long sum = 0;
            int nextPrime = 0;
            while ((nextPrime = sieve.Next()) < maxPrime)
            {
                sum += nextPrime;
            }

            watch.Stop();
            Console.WriteLine("{0} is the sum of all the primes below {1}", sum, maxPrime);
            Console.WriteLine("it took {0} milliseconds to calcluate this", watch.ElapsedMilliseconds);
        }
Esempio n. 4
0
        public static void Run()
        {
            int maxPrime = 2000000;

            Stopwatch watch = Stopwatch.StartNew();

            var  sieve     = new SieveOfPedro();
            long sum       = 0;
            int  nextPrime = 0;

            while ((nextPrime = sieve.Next()) < maxPrime)
            {
                sum += nextPrime;
            }

            watch.Stop();
            Console.WriteLine("{0} is the sum of all the primes below {1}", sum, maxPrime);
            Console.WriteLine("it took {0} milliseconds to calcluate this", watch.ElapsedMilliseconds);
        }