juyoubushiye1030 @ 2024-08-02 15:05:55
用的是埃氏筛。
#include<bits/stdc++.h>
using namespace std;
const int MAX = 9999999;//偶数位必然不是
int prime[MAX + 10];
void ai(){
for (int i = 2; i <= MAX; i++) {
prime[i] = 1;
}
for (int i = 2; i <= MAX; i++) {
if (prime[i]) {
for (int j = i * 2; j <= MAX; j += i){
prime[j] = 0;
}
}
}
}
bool check (int x) {
int a[20];
int flag = 0;
while (x) {
a[flag] = x % 10;
x /= 10;
flag ++;
}
for (int i = 0;i < flag /2; i++){
if (a[i] != a[flag - 1 - i])return 0;
}
return 1;
}
int main() {
ai();
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++) {
if (check(i) && prime[i])cout << i << endl;
}
return 0;
}