Advertisement
Guest User

Sieve Of Eratosthenes

a guest
Oct 29th, 2016
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SieveOfErathosthen
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. bool[] A = new bool[n];
  16. for (int i = 2; i < n; i++)
  17. {
  18. A[i] = true;
  19. }
  20. for (int i = 2; i < n; i++)
  21. {
  22. if (A[i])
  23. {
  24. for (int j = 2; (j * i) < n; j++)
  25. {
  26. A[j * i] = false;
  27. }
  28. }
  29. if (A[i])
  30. {
  31. Console.Write("{0} ", i);
  32. }
  33. }
  34. Console.WriteLine();
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement