nassss

Untitled

Jan 10th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _3._Prime_Triangle
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. int counter = 0;
  12. List<int> primeNumbers = new List<int>();
  13.  
  14. for (int i = 1; i <= n; i++)
  15. {
  16. for (int j = 1; j <= i; j++)
  17. {
  18. if (i % j == 0)
  19. {
  20. counter++;
  21. }
  22. else
  23. {
  24. continue;
  25. }
  26. }
  27. if (counter == 2 || i == 1)
  28. {
  29. primeNumbers.Add(i);
  30. for (int k = 1; k <= i; k++)
  31. {
  32. if (primeNumbers.Contains(k))
  33. {
  34. Console.Write(1);
  35. }
  36. else
  37. {
  38. Console.Write(0);
  39. }
  40. }
  41. Console.WriteLine();
  42. }
  43. counter = 0;
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment