dsfgsdf @ 2023-08-24 17:41:34
#include<bits/stdc++.h>
using namespace std;
int n,geshu=0,b;
int is_prime(int x){
if(x==1||x==0) return 0;
for(int i=3;i*i<=x;i+=2){
if(x%i==0) return 0;
}
return 1;
}
int cao(int k){
if(k>=10 && k<100 && k!=11 || k>=1000 && k<10000)return 0;
if(k>=100000 && k<1000000 || k>=10000000 && k<100000000)return 0;
return 1;
}
int is_huiwen(int x){
int y=0,c=0,d=0;
y=x;
while(y!=0){
c=y%10;
d=d*10+c;
y/=10;
}
if(d==x) return 1;
else return 0;
}
int main(){
scanf("%d%d",&n,&b);
if(n%2==0) n++;
if(b%2==0) b--;
b=min(b,9999999);
for(int i=n;i<=b;i+=2){
if(cao(i)==0) continue;
if(is_prime(i)==0||is_huiwen(i)==0){
continue;
}
printf("%d\n",i);
}
return 0;
}
by zvzvzgdfdw @ 2023-08-24 17:44:59
@lfxxzms
#include<bits/stdc++.h>
using namespace std;
int l, r;
bool check1(int x)//检查位数
{
if((1000 <= x && x <= 9999) || (100000 <= x && x <= 999999)) return 0;//不知道&&和||优先级的可以打个括号
return 1;
}
bool check2(int x)//检查是否回文
{
int a[20], flag = 1;//反正开得下,多开点
while (x > 0)
{
a[flag] = x % 10;
x /= 10;
flag++;
}
for (int i = 1; i <= flag / 2; i++)
if(a[i] != a[flag-i]) return 0;//不符合回文
return 1;
}
bool check3(int x)//检查是否为质数
{
if(x == 2) return 1;
for(int i = 2; i <= sqrt(x); i++)
if(x % i == 0) return 0;
return 1;
}
int main()
{
scanf("%d %d", &l, &r);
if(l == 2) printf("2\n");//一定要注意2!!!
if(l % 2 == 0) l++;
r = min(9999999, r);//再大的数都不可能是回文质数
for(int i = l; i <= r; i = i + 2)//枚举每一个奇数
{
if(check1(i) == 0) continue;
if(check2(i) == 0) continue;
if(check3(i) == 0) continue;
printf("%d\n", i);//printf会比cout快很多
}
return 0;
}
by dsfgsdf @ 2023-08-24 17:46:45
@zvzvzgdfdw
这不是题解吗??我看过. .......
by CJ07 @ 2023-08-24 17:49:52
@lfxxzms 其实你可以学一下线性筛
by CJ07 @ 2023-08-24 17:50:21
@Ifxxzms 然后你就能
by CJ07 @ 2023-08-24 17:52:35
或者你把
by dsfgsdf @ 2023-08-24 18:04:30
@CJ07 谢大佬