88分,最后一点超时了QAQ

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

zyx20090708 @ 2023-08-03 15:43:32

#include<bits/stdc++.h>
using namespace std;
bool v[100000001];
void get_prime(int n){
    memset(v,true,sizeof(v));
    v[1] = false;
    int b = sqrt(n);
    for(int i=2;i<=b;i++){
        if(v[i]){
            for(int j=2;j<=n/i;j++) v[i*j] = false;
        }
    }
}
bool is_huiwen(int m){
    int t=m,ans = 0;
    while(t!=0){
        ans +=t%10;
        ans*=10;
        t/=10;
    }
    return m*10 == ans;
}
int main(){
    int a,b;
    cin>>a>>b;
    if(a>=100000000)a=9999999;
    get_prime(b);
    if(a>b) return 0;
    if(a%2==0) a++;
    for(int j=a;j<=b;j+=2){
        if(v[j]&&is_huiwen(j)) cout<<j<<endl;
    }
    return 0;
}

by problemThief @ 2023-08-03 15:57:25

先判断回文数


by problemThief @ 2023-08-03 15:57:31

@zyx20090708


by wzb13958817049 @ 2023-08-03 15:58:43

@zyx20090708 告诉你个不靠谱的方法【狗头】,开o2


by Magus @ 2023-08-03 15:59:18

六十五万留名


by getfa114 @ 2023-08-03 16:03:18

实际上你可以本地打表,时间复杂度O(1)


by 立柱已选162534 @ 2023-08-03 16:09:32

考古(


by liuguanzhou @ 2023-08-03 16:38:56


by gongziwen @ 2023-08-03 16:43:52


by zyx20090708 @ 2023-08-03 16:45:24

@Rain_sun 不行QAQ


by zyx20090708 @ 2023-08-03 16:46:35

@Bernie_qwq ???


| 下一页