1. 程式人生 > >python實現判斷200以內可逆素數(整數顛倒也為素數)

python實現判斷200以內可逆素數(整數顛倒也為素數)

def judge(i):
    for j in range (2,i//2):
        if i%j==0:
            return 0
    return 1
print(2)
for i in range(3,201):
    if i<10 and judge(i)==1 :
            print(i)
    if i>10 and i<100 and judge(i)==1:
        if judge(i%10*10+i//10%10)==1:
            print(i)
    if i>100 and judge(i)==1: 
        if judge(i%10*100+((i//10)%10)*10+((i//10)//10))==1:
            print(i)