💡문제접근

  • 팰린드롬인지 아닌지를 판별하는 함수와 소수인지 아닌지를 판별하는 함수 두 개를 작성해서 두 개 다 True를 반환하는 N보다 크거나 같은 가장 작은 수를 출력한다.

💡코드(메모리 : 30616KB, 시간 : 304ms)

import sys
input = sys.stdin.readline

def Palindrome(x):
    x = str(x)
    if x == x[::-1]:
        return True
    else:
        return False

def prime(x):
    if x == 1:
        return False
    else:
        for i in range(2, int(x**0.5)+1):
            if x % i == 0:
                return False
        return True

N = int(input().strip())
while True:
    if Palindrome(N) and prime(N):
        print(N)
        break
    N += 1

💡소요시간 : 5m

0개의 댓글