하루 한 접시

[백준] 1747번: 소수&팰린드롬 [C#]

NaZZU 2024. 4. 23. 22:12

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
 
namespace 연습장
{
    internal class Program
    {
        static StringBuilder sb = new StringBuilder();
        static void Main(string[] args)
        {
            using var reader = new StreamReader(Console.OpenStandardInput());
            using var print = new StreamWriter(Console.OpenStandardOutput());
 
            _1747_boj boj = new _1747_boj();
 
            boj.boj_1747();
 
        }
    }        
    internal class _1747_boj
    {
        public int[] prime = new int[1_000_001];
        public int[] pal = new int[1_000_001];
        public List<int> res = new List<int>();
 
        public void boj_1747()
        {
            int input = int.Parse(Console.ReadLine());
 
            while (true)
            {
                if (is_prime(input))
                    if (is_pal(input.ToString()))
                    {
                        res.Add(input);
                        break;
                    }
                input++;
            }
            Console.WriteLine(res[0]);
 
        }
        public bool is_prime(int num)
        {
            if (num == 1)
                return false;
            else if (num <= 3)
                return true;
            for (int j = 2; j <= Math.Sqrt(num); j++)
            {
                if (num % j == 0)
                    return false;
            }
            return true;
        }
        public bool is_pal(string num)
        {
            for (int i = 0; i < num.Length / 2; i++)
            {
                if (num[i] != num[num.Length - i - 1])
                    return false;
            }
            return true;
        }
    }
}
 
cs

왜 틀렸는지 함참을 고민하고있었는데, 문제를 다시 읽어보니 ''''같거나'''' 큰 값을 구하라는 거였다....