Run ID:66979
提交时间:2024-03-12 19:30:29
#include <iostream> using namespace std; //G VAR const int G_MAX_SIZE = 100005; bool G_NOT_PRIME[G_MAX_SIZE] = { false };//false 代表是素数 //FUNC void getPrimesTable() { G_NOT_PRIME[0] = G_NOT_PRIME[1] = true; for (int i = 2; i < G_MAX_SIZE; i++) { if (!G_NOT_PRIME[i]) { for (int j = i + i; j < G_MAX_SIZE; j += i) { G_NOT_PRIME[j] = true; } } } } class Sol { public: Sol() {} Sol(int x, int y) : m_from(x), m_end(y) { } ~Sol() {} void showAns() { bool isFirst = true; for (int i = m_from; i <= m_end; i++) { if (G_NOT_PRIME[i] == false) { int reverse_i = getReverse(i); if (G_NOT_PRIME[reverse_i] == false) { if (isFirst) cout << i; else cout << ',' << i; isFirst = false; } } } if (isFirst) cout << "No"; } int getReverse(int x) { int ans = 0; while (x) { ans = ans * 10 + x % 10; x /= 10; } return ans; } private: int m_from, m_end; }; int main() { int x, y; cin >> x >> y; Sol test(x, y); test.showAns(); system("pause"); return 0; }