1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include <bits/stdc++.h>
using namespace std;
bool isPalindrome(int x) { int arr[11], idx = 0; do { arr[idx++] = x % 10; x /= 10; } while (x); for (int i = 0, j = idx - 1; i < j; ++i, --j) if (arr[i] != arr[j]) return false; return true; }
bool isPrime(int x) { for (int i = 2; i <= sqrt(x); ++i) { if (x % i == 0) return false; } return true; }
int main() { int a, b; cin >> a >> b; if (b > 9999999) b = 9999999; for (int i = (a % 2 ? a : a + 1); i <= b; i += 2) { if (isPalindrome(i) && isPrime(i)) cout << i << endl; } return 0; }
|