0分求助
查看原帖
0分求助
1051378
hsy0824楼主2024/8/15 22:25
#include <bits/stdc++.h>
using namespace std;
bool huiwen(int x){
    int t = x;
    int cnt = 0;
    while (t != 0){
        cnt++;
        t /= 10;
    }
    int c[10],tmp = 0;
    for (int i = 0; i <= cnt-1; i++){
        c[i] = x % 10;
        x /= 10;
        tmp++;
    }
    for (int i = 1; i <= ceil(tmp/2); i++){
        if (c[i] != c[tmp+1-i]){
            return false;
        }
    }
    return true;
}
bool zhishu(int y){
    for (int j = 2; j*j <= y; j++){
        if (y % j == 0){
            return false;
        }
    }
    return true;
}
int main(){
    int a,b;
    cin >> a >> b;
    for (int k = a; k <= b; k++){
        if (huiwen(k) == true && zhishu(k) == true){
            cout << k << "\n";
        }
    }
    return 0;
}
2024/8/15 22:25
加载中...