Skip to content

Instantly share code, notes, and snippets.

@lasagnaphil
Created May 11, 2019 17:21
Show Gist options
  • Save lasagnaphil/b08c6912166d9aba8da1efa833967ee1 to your computer and use it in GitHub Desktop.
Save lasagnaphil/b08c6912166d9aba8da1efa833967ee1 to your computer and use it in GitHub Desktop.
5강 과제 답
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lec5_hw
{
class Program
{
static void Main(string[] args)
{
int n = 100;
bool[] sieve = new bool[n];
sieve[0] = false;
for (int i = 1; i < n; i++)
{
sieve[i] = true;
}
for (int i = 2; i < (int)Math.Sqrt(n); i++)
{
if (sieve[i-1])
{
for (int j = 2*i; j <= n; j += i)
{
sieve[j-1] = false;
}
}
}
for (int i = 1; i <= n; i++)
{
if (sieve[i-1])
{
Console.Write(i);
Console.Write(" ");
}
}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment