我的代码已经改到我的极限了,但最后一个测试点还是超时!那个测试点1.20s/44.61MB!请各位大佬帮忙看看!!!
#include<iostream>
#include<string>
#include<vector>
using namespace std;
const int maxx=100000003;
vector<int> kkks;
vector<bool> kkk(maxx,1);
void ss(int b)
{
int cnt=0;
kkk[0]=0;
kkk[1]=0;
for(int i=2;i<=b;i++)
{
if(kkk[i])
{
kkks.push_back(i);
}
for(int j=0;j<kkks.size()&&i*kkks[j]<=b;j++)
{
kkk[i*kkks[j]]=0;
if(i%kkks[j]==0)
{
break;
}
}
}
return;
}
void hw(int a)
{
string s1,s2;
s1=to_string(a);
s2="";
for (int i=s1.size()-1; i>-1;i--)
{
s2.push_back(s1[i]);
}
if(s1==s2)
{
if(kkk[a])
{
cout<<a<<endl;
}
}
return;
}
int main()
{
int n,m;
cin>>n>>m;
ss(m);
for(int i = n; i <= m; i++)
{
hw(i);
}
return 0;
}
谢谢大家!!!