88分求助!剩下一个TLE

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

paulyang120 @ 2023-03-20 17:25:04


#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;
    }
}

by InversionShadow @ 2023-03-20 17:30:43

@yangzhengxi

最小的回文质数是 9989899


by Jackson_Miller @ 2023-03-20 18:33:08

@yuandingquan1101 应该是最大的吧


by InversionShadow @ 2023-03-20 18:58:59

@Jackson_Miller 对,打错了


|