55分,4个TLE,求助

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

HJM6 @ 2023-12-28 13:28:45

#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
bool lvs(long long x){
    if(x==11) return 1;
    if(x>9&&x<100) return 0;
    return 1;
}
bool zs(long long x){
    bool ib=0;
    if(x==1||x==0) return 0;
    for(int ia=2;ia<x;ia++){
        if(x%ia==0){
            return 0;
        }
    }
    return 1;
}
bool hws(long long x){
    long long ia=1;
    int z[10];
    while(x){
        z[ia]=x%10;
        ia++;
        x/=10;
    }
    for(int i=1;i<=ia/2;i++){
        if(z[i]!=z[ia-i]) return 0;
    }
    return 1;
}
int main(){
    scanf("%d %d",&a,&b);
    if(a%2==0){
        for(int i=a+1;i<=b;i+=2){
            if(lvs(i)){
                if(hws(i)) if(zs(i)) printf("%d\n",i);
            }
            else i=99;
        }
    }
    else{
        for(int i=a;i<=b;i+=2){
            if(lvs(i)){
                if(hws(i)) if(zs(i)) printf("%d\n",i);
            }
            else i=99;
        }
    }
    return 0;
}

|