[알고리즘/백준] 1747번 : 소수&팰린드롬(python)

유현민·2022년 3월 28일
0

알고리즘

목록 보기
75/253

소수이면서 팰린드롬인지 체크하면 된다.

def p(n):
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True


def isPalinDrome(n):
    length = len(n) // 2
    for i in range(length):
        if n[i] != n[-i - 1]:
            return False
    return True


N = int(input())
while True:
    if N == 1:
        pass
    elif isPalinDrome(str(N)) and p(N):
        break
    N += 1
print(N)
profile
smilegate megaport infra

0개의 댓글