求助!!!

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

ianwusb @ 2023-11-04 10:40:00

第一和第六WA,7TLE、9MLE,其他都RE

#include <stdio.h>
int main()
{
    int a,b,i,n,sum,j;
    scanf("%d%d",&a,&b);
    int huiwen[(b-a+10)];
    int PrimePalindromes[(b-a+10)];
    for (i=0;i<=(b-a+10);i++)
    {
        huiwen[i]=0;PrimePalindromes[i]=0;
    }

    for (i=a;i<=b;i++)
    {
        n=i;

        while (n>0)
        {
            sum=sum*10+n%10;
            n=n/10;
        }
        if (sum==i)
        {
            huiwen[i]=i;
            sum=0;
            continue;
        }
        else
        {
            sum=0;
            continue;
        }

    }
    for (i=0;i<=(b-a);i++)
    {
        for (j=2;j<=i;j++)
        {
            if (huiwen[i]%j==0)
            {
                break;
            }

        }
        if (i==j)
        {
            PrimePalindromes[i]=i;
        }
    }
    for (i=a;(i<=(b-a+1));i++)
    {
        if (PrimePalindromes[i]!=0)
        {
            printf("%d\n",PrimePalindromes[i]);
            continue;
        }

    }

}

by Sunny_Boybgfcxc @ 2023-11-04 11:05:46

我觉得,还是穷举更踏实


by Sunny_Boybgfcxc @ 2023-11-04 11:06:10

@jwr2023


|