Advertisement
Guest User

Untitled

a guest
May 19th, 2020
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5.  
  6. namespace PrimeTriangle
  7. {
  8.     class Program
  9.     {
  10.  
  11.         static bool IsPrime(int n)
  12.         {
  13.             if (n > 1)
  14.             {
  15.                 return Enumerable.Range(1, n).Where(x => n % x == 0)
  16.                     .SequenceEqual(new[] { 1, n });
  17.             }
  18.  
  19.             return false;
  20.         }
  21.         static void Main(string[] args)
  22.         {
  23.  
  24.             int n = int.Parse(Console.ReadLine());
  25.  
  26.             int count = 0;
  27.  
  28.             List<int> primes = new List<int>();
  29.  
  30.             for (int i = 1; i <= n; i++)
  31.             {
  32.                 if (IsPrime(i))
  33.                 {
  34.                     primes.Add(i);
  35.                 }
  36.             }
  37.             Console.WriteLine("1");
  38.  
  39.             for (int i = 0; i < primes.Count; i++)
  40.             {
  41.                 for (int j = 1; j <= primes[i]; j++)
  42.                 {
  43.                     if (IsPrime(j))
  44.                     {
  45.                         Console.Write("1");
  46.                     }
  47.                     else if (j == 1)
  48.                     {
  49.                         Console.Write("1");
  50.                     }
  51.                     else
  52.                     {
  53.                         Console.Write("0");
  54.                     }
  55.                 }
  56.                 Console.WriteLine();
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement