数组容量改了半天,还是AC不了,一会RE,一会又MLE的。。。TwT
#include<bits/stdc++.h>
using namespace std;
bool st[188888888], prime[188888888];
int hashtable[188888888];
int cnt;
void Euler(int u){ //欧拉筛建一个素数表
for(int i = 2; i <= u; i++){
if(!st[i]){
hashtable[cnt++] = i;
prime[i] = true;
}
for(int j = 0; hashtable[j] <= u / i; j++){
st[hashtable[j] * i] = true;
if(i % hashtable[j] == 0) break;
}
}
}
bool isPalindrome(int u){ //判断是否回文
string s = to_string(u);
string t(s.rbegin(), s.rend()); //逆序字符串
if(s == t) return true; //逆序的字符串与原来一样就是对的
else return false;
}
bool ws(int u){ //回文数,除了11,数字位数为偶数的数定不是素数
if(u >= 1000 and u < 10000) return false;
if(u >= 100000 and u < 1000000) return false;
if(u >= 10000000 and u < 100000000) return false;
return true;
}
int main(){
cin.tie(0)->sync_with_stdio(false);
int a, b;
cin >> a >> b;
if(a % 2 == 0) ++a; //各位为偶数必不是素数
Euler(b);
for(int i = a; i <= b; i += 2){
if(ws(i) == false) continue;
if(prime[i] and isPalindrome(i)) cout << i << endl;
}
return 0;
}