就只有#8测试点错了,这是为什么呢?

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

KT1001 @ 2024-04-01 16:52:32

#include <iostream>
#include <stdio.h>
#include <bitset>
#include <time.h>

using namespace std;

const int maxn = 1e8;
bitset<maxn> pri;
int primes[maxn], palind[maxn], result[maxn], pp = 0, k = 0;

void PalindPrimes(int result[], int primes[], int b){
    for(int i = 2; i <= b; i++){
        if(!pri[i]) {
            primes[++pp] = i;   //素数
            int t = primes[pp];
            int m = 0;
            while(t > 0){
                int temp = t % 10;
                m = m * 10 + temp;
                t /= 10;
            }
            if(m == primes[pp]) result[k++] = m; //此素数是否回文          
        }
        for(int j = 1; j <= pp && i * primes[j] <= b; j++){
            pri[primes[j] * i] = 1;
            if(i % primes[j] == 0)  break;
        }
    }
}

int main()
{
    int a,b;
    scanf("%d%d", &a,&b);
    PalindPrimes(result, primes, b);    //生成从2到b的所有素数

    int i = -1;
    while(result[++i] < a);

    int j = -1;
    while(result[++j] < b) if(result[j] == 0) break;

    for(i; i < j; i++) 
    {
        cout << result[i] << "\n";
    } 

    return 0; 
}

|