MLE on #9 奆佬求助

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

Geirangerfjard @ 2022-12-28 15:22:59

#include <iostream>
#include <cstring>
#define int long long

const int N = 100000001;

using namespace std;

bool is_prime[N];
int p[N];
int a,b;

void pri()
{
    memset(is_prime,1,sizeof(is_prime));
    int np=0;
    for (int i=2;i<=b;i++)
    {
        if(is_prime[i]) p[np++]=i;
        for (int j=0;j<np&&i*p[j]<=b;j++)
        {
            is_prime[i*p[j]]=0;
            if(i%p[j]==0) break;
        }
    }
}

bool judge(int x)
{
    int temp=0;
    int k=x;
    while(k)
    {
        temp=temp*10+k%10;
        k/=10;
    }
    return (temp==x);
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cin >> a >> b;
    pri();
    for (int i=a;i<=b;i++)
    {
        if(is_prime[i]&&judge(i)) cout << i << endl;
    }
}

by Geirangerfjard @ 2022-12-28 15:43:07

ok我逝逝


by Geirangerfjard @ 2022-12-28 15:43:44

c过了,感谢奆佬


by Kevin_Mamba @ 2022-12-28 15:44:15

@Alone_Helpless 你的 define 一直是 long long。

去掉改成 int。


by Geirangerfjard @ 2022-12-28 15:45:13

好的,过了 @2124Kobe


上一页 |