大佬们帮我看看出什么问题了呗,交上去出现几个tle

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

CR7syn @ 2022-11-28 23:18:25

#include<stdio.h>
#include<math.h>

int main()
{
    int t,palindrome=0,i,a,b,y,n,g;
    scanf("%d %d",&a,&b);
    for(i=a;i<=b;i++)
    {
        palindrome = 0;
        y = 2; 
        n = i % y;
        while (n != 0)
        {
            y++;
            n = i % y;

        }
        if (i == y)
        {
            n = i;
            for (; n != 0; n /= 10)
            {
                t = n % 10;
                palindrome = palindrome * 10 + t;
            }
            if (palindrome == i)
            {
                printf("%d", i);
                printf("\n");
            }
        }

    }
    return 0;
}

by ZVitality @ 2022-11-29 08:29:26

时间复杂度炸了。(a=5,b=10^9 一个一个判断肯定不行)


|