2024-03-30 23:52:51

 

두 수 사이의 소수들을 몽땅 구해다가 출력해주면 된다.

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