Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace PrimeTriangle
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<int> primes = new List<int>();
- int count = 1;
- for (int i = 2; i <= n; i++)
- {
- count = 0;
- for (int j = 1; j <= i; j++)
- {
- if (i % j == 0)
- {
- count++;
- }
- }
- if (count == 2)
- {
- primes.Add(i);
- }
- }
- primes.Insert(0, 1);
- for (int rows = 1; rows <= primes.Count; rows++)
- {
- for (int cols = 1; cols <= primes[rows - 1]; cols++)
- {
- if (primes.Contains(cols))
- {
- Console.Write("1");
- }
- else
- {
- Console.Write("0");
- }
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment