liruizhou_lihui @ 2023-10-17 20:10:18
#include<bits/stdc++.h>
using namespace std;
bool judgement_prime_number(long long x)
{
if(x<=1)return 0;
for(long long i=2;i<sqrt(x);i++)
{
if(x%i==0)return 0;
}
return 1;
}
bool judgement_Palindromes(long long y)
{
long long judgement=0;
long long y2=y;
while(y2!=0)
{
judgement=judgement*10+y2%10;
y2/=10;
}
if(judgement==y)return 1;
return 0;
}
bool Palindromes_AND_prime(long long x)
{
if(judgement_prime_number(x) && judgement_Palindromes(x))return 1;
return 0;
}
int main()
{
long long n,m;
cin>>n>>m;
for(long long i=n;i<=m;i++)
{
if(Palindromes_AND_prime(i))cout<<i<<endl;
}
return 0;
}
by wanglongye @ 2023-10-21 17:27:59
#include<bits/stdc++.h>
using namespace std;
bool judgement_prime_number(long long x)
{
if(x<=1)return 0;
for(long long i=2;i<=sqrt(x);i++)//不要漏了i正好等于sqrt(x)的情况
{
if(x%i==0)return 0;
}
return 1;
}
bool judgement_Palindromes(long long y)
{
long long judgement=0;
long long y2=y;
while(y2!=0)
{
judgement=judgement*10+y2%10;
y2/=10;
}
if(judgement==y)return 1;
return 0;
}
bool Palindromes_AND_prime(long long x)
{
if(judgement_Palindromes(x)&&judgement_prime_number(x))return 1;//先判断回文再判断素数速度更快
return 0;
}
int main()
{
long long n,m,l=10000000;
cin>>n>>m;
if (n % 2 == 0) n++;
for(long long i=n;i<=min(m,l);i += 2)//(这里是不是只看奇数无所谓了)最大的一个不超过10000000(看了题解才知道:偶数位的回文数都是11的倍数)
{
if(Palindromes_AND_prime(i))cout<<i<<endl;
}
return 0;
}
(不一定改对了,你运行一下看一看)