P1217 [USACO1.5] 回文质数 Prime Palindromes

zhuangshanjbin @ 2023-04-19 15:23:16


#include<bits/stdc++.h>
using namespace std;
int p,m;
void ss(int k)
{
    for(int j=3;j*j<=k;j+=2)
    {
        if(k%j==0)
            return;
    }
    cout<<k<<endl;
}
bool hui(int x)
{
    p=x;
    m=0;
    while(p>0)
    {
        m=m*10+p%10;
        p/=10;
    }
    if(m==x)
        return true;
    else
        return false;
}
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%2==0)
        a++;
    for(int i=a;i<=b;i+=2)
    {
        if(hui(i)==1)
            ss(i);
        if(i+1==2)
            cout<<2<<endl;
    }
}

|