You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
731 B
33 lines
731 B
#include<bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 1e8 + 10;
|
|
int primes[N], cnt;
|
|
bool st[N];
|
|
void get_primes(int n) {
|
|
for (int i = 2; i <= n; i++) {
|
|
if (!st[i]) primes[cnt++] = i;
|
|
for (int j = 0; primes[j] <= n / i; j++) {
|
|
st[primes[j] * i] = true;
|
|
if (i % primes[j] == 0) break;
|
|
}
|
|
}
|
|
}
|
|
bool isHWS(int num) {
|
|
int t = num, ans = 0;
|
|
while (t) {
|
|
ans = ans * 10 + t % 10;
|
|
t /= 10;
|
|
}
|
|
return ans == num;
|
|
}
|
|
int main() {
|
|
int a, b;
|
|
cin >> a >> b;
|
|
if (b >= 1e7) b = 1e7;
|
|
get_primes(b);
|
|
for (int i = a; i <= b; i++)
|
|
if (!st[i] && isHWS(i))
|
|
cout << i << endl;
|
|
return 0;
|
|
} |