有没有大佬看看有什么问题,就前两个过了,后面都是RE

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

lym61 @ 2023-11-03 17:48:06

#include<stdio.h>
#include<stdbool.h>
int prime[2000];
int cur;
bool status[1000000001];
void Euler_s(int n)
{
    status[0] = 1; status[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        if (status[i] == 0) prime[++cur] = i;
        for (int j = 1; j <= cur; j++)
        {
            if (i * prime[j] > n) break;
            status[i * prime[j]] = 1;
            if (i % prime[j] == 0) break;
        }
    }
}
void isPalindrome(int a)
{
    for (int j = 1; j <= cur; j++)
    {
        int sum = 0, i = 0;
        int at = prime[j];
        while (sum < at)
        {
            i = at % 10;
            at /= 10;
            sum *= 10;
            sum += i;
        }
        if(((sum / 10)== at || sum == at) && (prime[j] >= a))
        {
            printf("%d\n", prime[j]);
        }
    }
}
int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    a=(5<=a)?a:5;
    b=(99999999<=b)?99999999:b;

    Euler_s(b);
    isPalindrome(a);

    return 0;
}

by Azzero @ 2023-12-02 14:12:14

cur是个什么奇怪的变量?


by lym61 @ 2023-12-03 00:15:56

@Azzero 记录prime数组有效长度的


上一页 |