Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace ExamPreparation
- {
- class Startup
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- List<int> primes = new List<int>();
- bool isPrime = true;
- for (int i = 2; i <= n; i++)
- {
- for (int k = 2; k <= (int)Math.Sqrt(i); k++)
- {
- if (i % k == 0)
- {
- isPrime = false;
- }
- }
- if (isPrime)
- {
- primes.Add(i);
- }
- isPrime = true;
- }
- Console.WriteLine(string.Join(" ", primes));
- }
- }
- }
Add Comment
Please, Sign In to add comment