두 수 사이의 소수들을 몽땅 구해다가 출력해주면 된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
namespace 연습장
{
internal class Program
{
static void Main(string[] args)
{
using var reader = new StreamReader(Console.OpenStandardInput());
using var print = new StreamWriter(Console.OpenStandardOutput());
StringBuilder sb = new StringBuilder();
int[] input = Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
int a = Math.Min(input[0], input[1]);
int b = Math.Max(input[0], input[1]);
for (int i = a; i <= b; i++)
{
if (is_Prime(i))
sb.Append(i + "\n");
}
print.WriteLine(sb);
}
static bool is_Prime(int num)
{
if (num <= 1)
return false;
for (int i = 2; i <= Math.Sqrt(num); i++)
{
if (num % i == 0)
return false;
}
return true;
}
}
}
|
cs |
'하루 한 접시' 카테고리의 다른 글
[백준] 17103번: 골드바흐 파티션 [C#] (0) | 2024.03.31 |
---|---|
[백준] 4948번: 베르트랑 공준 [C#] (0) | 2024.03.31 |
[백준] 4134번: 다음 소수 [C#] (0) | 2024.03.30 |
[백준] 2485번: 가로수 [c#] (0) | 2024.03.29 |
[백준] 1934번: 최소공배수 [C#] (0) | 2024.03.28 |