为啥TLE4个点

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

YSchencheche @ 2023-11-08 14:03:25

#include<bits/stdc++.h>
using namespace std;
bool p(int e)
{
    for(int i=2;i<=sqrt(e);i++)
    {
        if(!(e%i))
        {
            return 0;
        }
    }
    return 1;
}
int main()
{
    int a,b;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        stringstream Q;
        Q<<i;
        string q;
        Q>>q;
        string w =q;
        reverse(q.begin(),q.end());
        if(p(i) && q==w)
        {
            cout<<i<<"\n";
        }
    }
    return 0;
} 

请问为啥??


by zhaohanwen @ 2023-11-08 14:09:35


by YSchencheche @ 2023-11-08 17:05:27

@zhaohanwen

大佬,那咋办啊


by zhaohanwen @ 2023-11-08 17:18:14

@chenxingran594777 题解里讲了。


|