总有一个点过不了,求助

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

YWK_Liverpool @ 2023-07-18 23:06:44

代码如下

#include<bits/stdc++.h>
using namespace std;
bool book[10000001];
void prime(int b) {
    memset(book, true, sizeof(book));
    book[1]=false;
    int n=sqrt(b);
    for (int i=2;i<=n;i++) {
        if (book[i]) {
            for (int j=2;j<=b/i;j++)
                book[i*j]=false;
        }
    }
}
int main(){
    cin.tie(0);
    cout.tie(0);
    int a,b,num;
    bool x=true;
    string numStr;
    cin>>a>>b;
    if(b>=10000000){
        b=9999999;
    }
    prime(b);
    for(int i=int(a/2)*2+1;i<b;i+=2){
        if((i==1000)||(i==100000)){
            i=i*10;
        }
        if(book[i]){
            numStr=to_string(i);
            num=numStr.length();
            for(int j=0;j<int(num/2);j++){
                if(numStr[j]!=numStr[num-j-1]){
                    x=false;
                    break;
                }
            }
            if(x==true){
                cout<<i<<endl;
            }
        }
        x=true;
    }
    return 0;
}

by 1234567890hh @ 2023-07-28 14:12:40

你说清楚啊是WA还是TLE啊


by YWK_Liverpool @ 2024-03-28 20:03:52

@1234567890hh WA


|