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
| #include <cstdio> bool isprime(int a) { for (int i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } bool isrever(int n) { int tmp = n, NEW = 0; while (tmp) { NEW = NEW * 10 + tmp % 10; tmp /= 10; } return NEW == n; } int n, ans; int main() { scanf("%d", &n); for (int i = 11; i <= n; i++) { if (isrever(i) && isprime(i)) { ans++; } } printf("%d", ans); return 0; }
|