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.
42 lines
847 B
42 lines
847 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]) continue;
|
|
primes[cnt++] = i;//都有哪些质数
|
|
for (int j = i + i; j <= n; j += i)
|
|
st[j] = true;
|
|
}
|
|
}
|
|
|
|
//是不是回文数
|
|
bool isHuiWen(int n) {
|
|
int i = n;
|
|
int m = 0;
|
|
while (i) {
|
|
m = m * 10 + i % 10;
|
|
i /= 10;
|
|
}
|
|
return m == n;
|
|
}
|
|
|
|
int main() {
|
|
int a, b;
|
|
cin >> a >> b;
|
|
if (b > 10000000) b = 10000000;
|
|
|
|
get_primes(b);
|
|
//primes[] 2--->b之间所有的质数
|
|
for (int i = 0; i < cnt; i++) {
|
|
if (primes[i] < a)continue;
|
|
if (isHuiWen(primes[i]))
|
|
cout << primes[i] << endl;
|
|
}
|
|
return 0;
|
|
} |