计蒜客 T1167 素数回文数的个数

水题~。

int n;

bool isprime(int x)
{
    if(x<2) return false;
    for(int i=2;i*i<=x;i++)
        if(x % i == 0)
            return false;
    return true;
}

bool palindrome(int x)
{
    int res=0,t=x;
    while(t)
    {
        res=res*10+t%10;
        t/=10;
    }
    return res==x;
}

int main()
{
    cin>>n;

    int res=0;
    for(int i=11;i<=n;i++)
        if(isprime(i) && palindrome(i))
            res++;
    cout<<res<<endl;
    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14615814.html