求助!样例都过了,只有11分。

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

lzy127 @ 2024-10-20 13:36:13


by DESTRUCTION_WA @ 2024-10-20 13:50:52

#include <bits/stdc++.h>
using namespace std;
bool prime(long long n){
    if(n == 2){
        return true;
    }
    if(n == 1 || n % 2 == 0){
        return false;
    }
    for(long long i = 3;i <= sqrt(n);i += 2){
        if(n % i == 0){
            return false;
        }
    }
    return true;
}
bool reverseandcheck(int a){
    int n = a,m = 0;
    while(n > 0){
        m = m * 10 + n % 10;
        n /= 10;
    }
    if(a == m){
        return true;
    }else{
        return false;
    }
}
int main() {

    int a,b;
    cin >> a >> b;
    if(a % 2 == 0){
        a++;
    }
    for(int i = a;i <= b;i += 2){
        if(reverseandcheck(i)){
            if(prime(i)){
                cout << i << endl;
            }
        }
    }

    return 0;
}

求关 @lzy127


by lzy127 @ 2024-10-20 16:31:55

@DESTRUCTION_WA 已关


|