就最后三点TLE了

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

rnf5114 @ 2023-04-16 07:48:27

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,l,s,g=0;
    bool flag;
    cin>>n>>l;
    if(n%2==0){
        n++;
    }
    for(int i=n;i<=l;i+=2){
        g=0;
        flag=1;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                flag=0;
                break;
            }
        }
        if(flag){
            s=i;
            while(s){
                g=g*10+s%10;
                s/=10;
            }
            if(g==i){
                cout<<g<<endl;
            }
        }
    }
}

by wsr_jason @ 2023-04-16 09:32:06

几个建议:


|