Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class EratosthenesAlgorithmPrimeNumbers
- {
- static void Main()
- {
- DateTime a1 = DateTime.Now;
- // Define the Array
- int length = 10000000;
- bool[] array = new bool[length];
- List<long> arrayPrime = new List<long>();
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = true;
- }
- // Get the prime numbers "Eratosthenes Algorithm"
- long j = 0;
- for (long i = 2; i < array.Length; i++)
- {
- if (array[i] == true)
- {
- arrayPrime.Add(i);
- j = i * i;
- }
- while (j < array.Length)
- {
- array[j] = false;
- j = j + i;
- }
- }
- // Print
- for (int i = 0; i < arrayPrime.Count - 100; i++)
- {
- Console.Write(arrayPrime[i] + " ");
- }
- Console.WriteLine();
- DateTime a2 = DateTime.Now;
- Console.WriteLine(a2 - a1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement