'commit'
This commit is contained in:
41
TangDou/LuoGuBook/L4_14_4.cpp
Normal file
41
TangDou/LuoGuBook/L4_14_4.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int N = 1e8 + 10;
|
||||
int primes[N], cnt; // primes[]存储所有素数
|
||||
bool st[N]; // st[x]存储x是否被筛掉
|
||||
void get_primes(int n) {
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (!st[i]) primes[cnt++] = i;
|
||||
for (int j = 0; primes[j] * i <= n; j++) {
|
||||
st[primes[j] * i] = true;
|
||||
if (i % primes[j] == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//是不是回文数
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user