超时了!求助大佬!

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

acmwriter @ 2022-11-08 23:26:39

#include<stdio.h>
int main()
{
    int a,b,i,j;int c,d=0;
    scanf("%d %d",&a,&b);
    for(i=a;i<=b;i++)
    {
        for(j=2;j<=i;j++)
        {
            if(i%j==0)break;
        }
        if(j==i)
        {
            while(i)
            {
                c=i%10;
                d=d*10+c;
                i/=10;
            }
            if(d==i)printf("%d\n",i);
        }
    }
    return 0;
}

by WangJingze @ 2022-11-08 23:35:30

这题要使用筛法,这边建议学习一下这个


|