求助

P1217 [USACO1.5] 回文质数 Prime Palindromes

XIJUN @ 2023-07-19 15:59:38

怎么办22分

#include<iostream>
using namespace std;
//判断是不是回文数
bool isnum(int a)
{
    int b = a;
    int c = 0;
    while (b > 0) {
        c = c * 10 + b % 10;
        b /= 10;
    }
    if (a == c) {
        return true;
    }
    else {
        return false;
    }
}
//判断是不是质数
bool iszhi(int a)
{
    for (int i = 2; i < a; i++) {
        if (a % i == 0) {
            return false;
        }
    }
    return true;
}
int main() {
    int a, b;
    cin >> a >> b;
    for (a; a <= b; a += 2) {
        if (isnum(a) && iszhi(a)) {
            cout << a << endl;
        }
        else {
            continue;
        }
    }
    return 0;
}

by wizard(偷开O2 @ 2023-07-21 23:24:48

@XIJUN 改main里的for循环

    int a, b;
    cin >> a >> b;
    for (int i=a;i<=b;i++) {
        if (isnum(i) && iszhi(i)) {
            cout << i << endl;
        }
    }

|