'commit'
This commit is contained in:
39
TangDou/LuoGuBook/P1217_2.cpp
Normal file
39
TangDou/LuoGuBook/P1217_2.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 100000010;
|
||||
|
||||
//欧拉筛
|
||||
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] <= 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() {
|
||||
//AC
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
if (b >= 1e7)b = 1e7;
|
||||
get_primes(b);
|
||||
for (int i = 0; i < cnt; i++)
|
||||
if (primes[i] >= a && isHWS(primes[i]))
|
||||
printf("%d\n", primes[i]);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user