Advertisement
Guest User

Sieve of Eratosthenes

a guest
May 9th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApp5
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int input = int.Parse(Console.ReadLine());
  11.  
  12. string arrString = "";
  13.  
  14. for (int i = 2; i <= input; i++)
  15. {
  16. bool isPrime = true;
  17.  
  18. for (int j = 2; j <= Math.Sqrt(i); j++)
  19. {
  20. if (i % j == 0)
  21. {
  22. isPrime = false;
  23. }
  24. }
  25.  
  26. if (isPrime)
  27. {
  28. arrString += i + " ";
  29. }
  30.  
  31. }
  32.  
  33. int[] arr = arrString.Split(' ').Select(int.Parse).ToArray();
  34.  
  35. Console.WriteLine(string.Join(" ", arrString));
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement