4948 베르트랑 공준
Console Programming/C# Console 2019. 12. 4. 10:01using System;
using System.Text;
namespace _4948
{
class Program
{
static void Main(string[] args)
{
while (true)
{
string str = Console.ReadLine();
if (str[0]=='0')
{
break;
}
int M = int.Parse(str);
int N = M * 2;
int cnt=0;
int[] arr = new int[N + 1];
for (int i = 2; i < N + 1; i++)
{
arr[i] = i;
}
for (int i = 2; i < N+1; i++)
{
if (arr[i] != 0)
{
for (int j = i * 2; j < N + 1; j += i)
{
arr[j] = 0;
}
}
}
for(int i =M+1; i<N+1; i++)
{
if(arr[i]==0)
{
}
else
{
cnt++;
}
}
Console.WriteLine(cnt);
}
}
}
}
'Console Programming > C# Console' 카테고리의 다른 글
백준 1152 단어의 개수 (0) | 2020.04.02 |
---|---|
백준 10872 팩토리얼 (0) | 2019.12.20 |
1929 소수 구하기 에라토스테네스의 체 (0) | 2019.12.04 |
2581 소수 (0) | 2019.12.03 |
Event와 Delegate를 사용한 Hero의 Move(), Attack() //Monster의 Hit() 구현 (0) | 2019.11.29 |