Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write a program that finds all prime numbers in the range [1...10 000 000]. Use the sieve of Eratosthenes algorithm (find it in Wikipedia).
- class FindsAllPrime
- {
- static void Main()
- {
- //Input
- int n = 10000000;
- int[] array = new int[n];
- array[0] = 1;
- array[1] = 1;
- array[2] = 0;
- //Solution
- for (int i = 2; i < Math.Sqrt(n); i++)
- {
- for (int j = 2; j*i < n; j++)
- {
- array[j*i] = 1;
- }
- }
- //Output
- for (int i = 0; i < n; i++)
- {
- if (array[i] == 0)
- {
- Console.WriteLine(i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement