收获了新模板:

bool isrever(int n)
{
    int tmp = n, NEW = 0;
    while (tmp)
    {
        NEW = NEW * 10 + tmp % 10;
        tmp /= 10;
    }
    return NEW == n;
}

判断回文数。

code:

#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;
}

2022/6/26