0
Follow
0
View

How to solve the problem of ## includo #?

cyj773 注册会员
2023-02-27 23:13

OJ or prompt time error ah, please tell me how to save time?

dongwei1529 注册会员
2023-02-27 23:13


#include 
using namespace std;

// 判断是否为回文数
bool isSymm(int a) {
    int j = a, k = 0;
    while (j > 0) {
        k = k * 10 + j % 10;
        j /= 10;
    }
    return k == a;
}

// 判断是否为质数
bool isPrime(int a) {
    if (a == 1) return false;
    if (a == 2) return true;
    for (int i = 2; i <= sqrt(a); i++) {
        if (a % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
        if (isSymm(i) && isPrime(i)) {
            cout << i << endl;
        }
    }
    return 0;
}

About the Author

Question Info

Publish Time
2023-02-27 23:13
Update Time
2023-02-27 23:13