Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Archives
Today
Total
관리 메뉴

Star_project

[인프런] 2. 자료구조와 알고리즘 입문 8. 뒤집은 소수 본문

코딩테스트/Python

[인프런] 2. 자료구조와 알고리즘 입문 8. 뒤집은 소수

star빛 2022. 7. 12. 11:46

 

import sys

from sklearn.utils import resample
sys.stdin=open("pythonalgorithm/섹션 2/8. 뒤집은 소수/in5.txt","rt")
n=int(input())
a=list(map(int, input().split()))
def reverse(x):
    res=0
    while x>0:
        t=x%10
        res=res*10+t
        x=x//10
    return res
def isPrime(x):
    if x==1:
        return False
    for i in range(2, x//2+1):
        if x%i==0:
            return False
            # false 당하면 if 문 끝남
    else:
        return True
        # for 문 이 False 안당하고 정상적으로 종료되면 else 문 실행

for x in a:
    tmp=reverse(x)
    if isPrime(tmp):
        print(tmp, end=' ')