HELP!!!!66pct

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

jonnyyuan @ 2024-01-02 20:41:36

#include <bits/stdc++.h>
using namespace std;
bool s(int a){
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
bool l(int a){
    int sum=0,q;
    int b=a;
    while(a>0){
        q=a%10;
        a=a-q;
        a=a/10;
        sum=sum*10+q;
    }
    if(sum==b){
        return 1;
    }

    else{
        return 0;
    }
}
int main(){
    int m,n;
    cin>>m>>n;
    for(int i=m;i<=n;i++){
        if(s(i)==1&&l(i)==1){
            cout<<i<<endl;
        }
    }
}

by 违规用户名971024 @ 2024-01-21 17:06:55

要先判断回文,再判断素数!


|