Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class SieveOfEratosthenes
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int currentPrime = 2;
- int[] numbers = Enumerable.Range(0, n + 1).ToArray();
- while (currentPrime < n)
- {
- for (int i = currentPrime * 2; i <= n; i += currentPrime)
- {
- numbers[i] = 0;
- }
- currentPrime++;
- while (numbers[currentPrime] < 2 && currentPrime < n)
- {
- currentPrime++;
- }
- }
- Console.WriteLine(string.Join(", ", numbers.Where(number => number >= 2)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement