救命啊c语言新手懵逼了,我该怎么改,求大佬

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

proyuan666 @ 2024-11-21 20:04:02

#include <stdio.h>
#include <stdbool.h>
bool zhishu( int x);
bool huiwen( int x);
bool OK( int x);

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    for ( int x = a; x <= b; x++)
    {
        if (OK(x))
        {
            printf("%d\n", x);
        }
    }
    return 0;
}
bool zhishu( int x)
{
    if (x < 2)
        return false;
    if (x == 2)
        return true;
    if (x % 2 == 0)
        return false;
    for ( int i = 3; i * i <= x; i = i + 2)
    {
        if (x % i == 0)
            return false;
    }
    return true;
}
bool huiwen( int x)
{
     int flag1 = 0, flag2 = x;
    while (x != 0)
    {
        flag1 = flag1 * 10 + x % 10;
        x = x / 10;
    }
    return flag2 == x;
}
bool OK(int x)
{
    return zhishu(x) && huiwen(x);
}

by MXT20121010 @ 2024-11-21 20:26:40

你的回文数判断的返回值错了 应该返回return flag1 == flag2;


by MXT20121010 @ 2024-11-21 20:28:32

改了只有66分 会TLE 自己优化 我最讨厌优化 要自己生成回文质数


by proyuan666 @ 2024-11-22 17:29:13

@MXT20121010好的非常感谢大佬


|