MLE88分求调
查看原帖
MLE88分求调
1432988
Yeonjun_0913楼主2024/10/12 14:11
#include <iostream>
#include <vector>
using namespace std;

vector<int> prime;
bool f[100000005];
int a,b;
void p(int n){
    f[1]=true;
    for (int i=2;i<=n;i++){
        if (!f[i]) prime.push_back(i);
        for (int j=0;j<prime.size()&&i*prime[j]<=n;j++){
            f[i*prime[j]]=true;
            if (i%prime[j]==0){
                break;
            }
        }
    }
}
bool check(int x){
    int d=x,res=0;
    while (d){
        res=res*10+d%10;
        d/=10;
    }
    return res==x;
}

int main (){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b;
    p(b);
    for (int i=a;i<=b;i++){
        if (!f[i]&&check(i)){
            cout << i << endl;
        }
    }
    return 0; 
}
2024/10/12 14:11
加载中...