Beispiel #1
0
        public static void Run()
        {
            var start = DateTime.Now;

            long number = 600851475143;
            int maxPrime = (int)Math.Floor(Math.Sqrt(number));
            var generator = new SieveOfEratosthenes(maxPrime, true);

            int largest = 0;
            foreach (int prime in generator.Primes)
            {
                Console.WriteLine(prime);
                if (number%prime == 0)
                    largest = prime;
            }

            Console.WriteLine("{0} is the largest prime factor of {1}", largest, number);
            Console.WriteLine("it took {0} seconds to calcluate this", DateTime.Now.Subtract(start).TotalSeconds);
        }
Beispiel #2
0
        public static void Run()
        {
            var start = DateTime.Now;

            long number    = 600851475143;
            int  maxPrime  = (int)Math.Floor(Math.Sqrt(number));
            var  generator = new SieveOfEratosthenes(maxPrime, true);

            int largest = 0;

            foreach (int prime in generator.Primes)
            {
                Console.WriteLine(prime);
                if (number % prime == 0)
                {
                    largest = prime;
                }
            }

            Console.WriteLine("{0} is the largest prime factor of {1}", largest, number);
            Console.WriteLine("it took {0} seconds to calcluate this", DateTime.Now.Subtract(start).TotalSeconds);
        }