EggyLuoguAccount @ 2024-10-07 16:59:24
#include<bits/stdc++.h>
using namespace std;
bool isPrime(long long j)
{
for(long long k=2;k<=sqrt(j);k++)
{
if(j%k==0) return false;
}
return true;
}
bool isReverse(long long j)
{
long long temp,backup;
backup=j;
while(backup!=0)
{
temp=temp*10+backup%10;
backup/=10;
}
if(temp==j) return true;
else return false;
}
int main()
{
long long a,b;
cin>>a>>b;
for(long long j=a;j<=b;j++)
{
if(j%2==0) continue;
if(isPrime(j)&&isReverse(j)) cout<<j<<endl;
}
return 0;
}
by liruizhou_lihui @ 2024-10-07 17:02:57
@EggyLuoguAccount 0和1要特判
by Lisuyang @ 2024-10-07 17:07:23
@EggyLuoguAccount
#include<bits/stdc++.h>
using namespace std;
const int N = 1e8 + 1;
bitset<N>vis;
bool isReverse(long long j)
{
string k = to_string(j);
string k2 = k;
reverse(k2.begin(), k2.end());
if(k==k2) return true;
else return false;
}
int main()
{
long long a,b;
cin>>a>>b;
for(int i = 2; i * i <= b; ++ i)
if(!vis[i]) for(int j = i * i; j <= b; j += i) vis[j] = 1;
//预处理质数
for(long long j=a;j<=b;j++)
{
if(j%2==0) continue;
if(!vis[j]&&isReverse(j)) cout<<j<<endl;
}
return 0;
}
by MLE_Automaton @ 2024-10-07 17:08:30
@EggyLuoguAccount 1是质数
by Lisuyang @ 2024-10-07 17:11:55
@ChenXiJie2013
1不是质数,数学该补补了
by MLE_Automaton @ 2024-10-07 17:12:35
@Lisuyang c说胡话了,1不是质数
by EggyLuoguAccount @ 2024-10-07 18:14:39
@liruizhou_lihui 谢谢~
by EggyLuoguAccount @ 2024-10-07 18:15:13
@Lisuyang 谢谢大佬~
by EggyLuoguAccount @ 2024-10-07 18:17:23
@ChenXiJie2013 谢谢~