nassss

Untitled

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