[Silver I] Title: 소수&팰린드롬, Time: 3540 ms, Memory: 34536 KB -BaekjoonHub

This commit is contained in:
SSUM
2025-02-16 16:02:09 +09:00
parent 33ec48e369
commit 21cd5a206f
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
# [Silver I] 소수&팰린드롬 - 1747
[문제 링크](https://www.acmicpc.net/problem/1747)
### 성능 요약
메모리: 34536 KB, 시간: 3540 ms
### 분류
브루트포스 알고리즘, 수학, 정수론, 소수 판정, 에라토스테네스의 체
### 제출 일자
2025년 2월 16일 16:00:51
### 문제 설명
<p>어떤 수와 그 수의 숫자 순서를 뒤집은 수가 일치하는 수를 팰린드롬이라 부른다. 예를 들어 79,197과 324,423 등이 팰린드롬 수이다.</p>
<p>어떤 수 N (1 ≤ N ≤ 1,000,000)이 주어졌을 때, N보다 크거나 같고, 소수이면서 팰린드롬인 수 중에서, 가장 작은 수를 구하는 프로그램을 작성하시오.</p>
### 입력
<p>첫째 줄에 N이 주어진다.</p>
### 출력
<p>첫째 줄에 조건을 만족하는 수를 출력한다.</p>

View File

@@ -0,0 +1,29 @@
import sys
import math
input = sys.stdin.readline
def pellindrom(num):
num = str(num)
num_len = len(num) // 2
for i in range(num_len):
if(num[i]!=num[-(i+1)]):
return False
return True
def isPrime(num):
if (num==1):
return False
for i in range(2, (int(math.sqrt(num))+1)):
if num%i == 0:
return False
return True
N = int(input())
while True:
if (isPrime(N) and pellindrom(N)):
print(N)
break
else:
N+=1