lijuncheng_1207 @ 2023-07-27 18:07:53
#include <bits/stdc++.h>
using namespace std;
int n,m,cnt;
bool prime(int x){
for(int i=2;i<=sqrt(x);i++) {
if(x%i==0)
return 0;
}
return 1;
}
bool flag(int x){
string s=to_string(x);
string s1=s;
reverse(s.begin(),s.end());
if(s1==s){
return 1;
}
return 0;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=n;i<=m;i++) {
if(flag(i)&&prime(i)){
cout<<i<<endl;
}
}
return 0;
}
by zbyzby666 @ 2023-07-27 18:13:18
垃圾,这都不会,太菜了
by xvl_ @ 2023-07-27 18:14:34
建议禁言
by xvl_ @ 2023-07-27 18:14:42
@zbyzby666
by lijuncheng_1207 @ 2023-07-27 18:23:24
@zbyzby666 你个小蓝名,有什么资格嘲笑我,你有没有教养 你可以不回复,但我绝不允许你在我的帖子里骂人
by LiJoQiao @ 2023-07-27 18:46:04
@Lijuncheng1207 可以考虑枚举回文数来减少枚举次数提高效率
by LiJoQiao @ 2023-07-27 18:46:53
另外偶数位数的回文数都不是质数,可证明
by Konjac_Jelly_6 @ 2023-07-27 18:48:18
因为在本题中回文质数都是奇数
for(int i=n;i<=m;i+=2)
by DioxygenDifluoride @ 2023-07-27 18:50:32
@Lijuncheng1207 测试得出,一亿以内最大的回文素数为 9989899,后面没有了。
#include <bits/stdc++.h>
using namespace std;
int n,m,cnt;
bool prime(int x){
for(int i=2;i<=sqrt(x);i++) {
if(x%i==0)
return 0;
}
return 1;
}
bool flag(int x){
string s=to_string(x);
string s1=s;
reverse(s.begin(),s.end());
if(s1==s){
return 1;
}
return 0;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0),cout.tie(0);
cin>>n>>m;
if(m>9989899)m=9989899;
for(int i=n;i<=m;i++) {
if(flag(i)&&prime(i)){
cout<<i<<endl;
}
}
return 0;
}
by lijuncheng_1207 @ 2023-07-27 18:50:51
@Konjac_Jelly_6 44
by DioxygenDifluoride @ 2023-07-27 18:51:22
附: @zbyzby666 垃圾,这种代码都改不来,太菜了