问题标题: 酷町堂:2646 回文质数

0
0
已解决
胡景波
胡景波
中级光能
中级光能

#include<iostream>
#include<cmath>
using namespace std;
bool judge(int x){
    if(x==1) return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0){
            return false;
        }
    }
    return true;
}
bool f(int y){
    int s=0;
    int m=y;
    while(m){
        s=s*10+m%10;
        m/=10;
    }
    if(s==y){
        return true;
    }
    else{
        return false;
    }
}
int main(){
    int m,n,cnt=0;
    cin>>m>>n;
    for(int i=m;i<=n;i++){
        if(judge(i)&&f(i)){
            cout<<i<<endl;
        }
    }
    return 0;
}

超时第三个测试点1060ms 88分


0
0
蔡乐毅
蔡乐毅
高级光能
高级光能

把回文函数最后的判断去掉,改成return s==y;

我要回答