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
678 B

#include<bits/stdc++.h>
using namespace std;
const int N = 1e8 + 10;
//判断一个数是不是质数
bool isPrime(int n) {
if (n < 2) return false;
for (int i = 2; i <= n / i; i++)
if (n % i == 0) return false;
return true;
}
//回文数的判定
bool isHWS(int x) {
int t = x, ans = 0;
while (t) {
ans = ans * 10 + t % 10;
t /= 10;
}
return ans == x;
}
int main() {
//3个点TLE
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++)
if (isPrime(i) && isHWS(i))
cout << i << endl;//如果既是质数同时也是回文数,就输出。
return 0;
}