ljx_gkx @ 2023-03-26 17:22:46
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e8+10;
int a, b;
int primes[N]; //质数的数组!
bool st[N];
int cnt;
void is_prime(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 huiwen (int nums)
{
string str = to_string(nums);
int l=0, r=str.size()-1;
while (l < r)
{
if (str[l++] != str[r--])
return false;
}
return true;
}
int main()
{
cin >> a >> b;
is_prime(b);
for (int i=0; i < cnt; i ++)
{
if (primes[i] >= a && primes[i] <= b)
if (huiwen(primes[i]))
cout << primes[i] << endl;
}
return 0;
}
by cyyy0408 @ 2023-03-27 12:01:56
by cyyy0408 @ 2023-03-27 19:03:48
by cyyy0408 @ 2023-03-27 22:32:02