王大锤现在是一个优秀的节目主持人。他正在主持一档音乐选秀节目,可谁知选手个个奇葩,从盲人司机到逃狱犯人各种大跌眼镜。而Hold住了他们的大锤本以为功德圆满,但万万没想到,最后一个选手的出现使他彻底崩盘…该选手上来就挑战锤锤的智商,(我也不知道该选手是干什么的。。。可能是精神病院里跑出吧!!!),给锤锤出了一道变态的题,给出两个整数a,b,先让他从a,b间的整数中挑出素数,再从挑出的素数中挑出回文数,够BT吧,为了挽回 锤锤 的面子,导演决定让作为ACMER的你来帮他回答这个问题(帮帮他吧)。。。
输入格式
输入有多组数据。每行有两个数a和b(0<=a,b<=1000000000)。
0 0 表示输入结束。
输出
输出所有介于a,b间满足题目要求的整数(具体格式见样例)。
样例输入
1 10
0 0
样例输出
2 3 5 7
提示[+]
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int f(int t)
{
if(t<2)
return 0;
for(int i=2; i*i<=t; i++)
if(t%i==0)
return 0;
return 1;
}
int s[1000000];
int main()
{
int j=0;
for(int a=1; a<10; a++)
s[j++]=a;
for(int a=1; a<10; a++)
s[j++]=a*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
s[j++]=a*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
s[j++]=a*1000+b*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
for(int c=0; c<10; c++)
s[j++]=a*10000+b*1000+c*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
for(int c=0; c<10; c++)
s[j++]=a*100000+b*10000+c*1000+c*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++ )
for(int c=0; c<10; c++)
for(int d=0; d<10; d++)
s[j++]=a*1000000+b*100000+c*10000+d*1000+c*100+b*10+a;
int m,n;
while(cin>>m>>n)
{
if(m==0&&n==0)
break;
if(m>n)
swap(m,n);
int k=0;
for(int i=0; i<j; i++ )
if(s[i]>=m&&s[i]<=n&&f(s[i]))
{
if(k)
cout<<" ";
else
k=1;
cout<<s[i];
}
cout<<endl;
}
return 0;
}
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int f(int t)
{
if(t<2)
return 0;
for(int i=2; i*i<=t; i++)
if(t%i==0)
return 0;
return 1;
}
int s[1000000];
int main()
{
int j=0;
for(int a=1; a<10; a++)
s[j++]=a;
for(int a=1; a<10; a++)
s[j++]=a*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
s[j++]=a*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
s[j++]=a*1000+b*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
for(int c=0; c<10; c++)
s[j++]=a*10000+b*1000+c*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++)
for(int c=0; c<10; c++)
s[j++]=a*100000+b*10000+c*1000+c*100+b*10+a;
for(int a=1; a<10; a++)
for(int b=0; b<10; b++ )
for(int c=0; c<10; c++)
for(int d=0; d<10; d++)
s[j++]=a*1000000+b*100000+c*10000+d*1000+c*100+b*10+a;
int m,n;
while(cin>>m>>n)
{
if(m==0&&n==0)
break;
if(m>n)
swap(m,n);
int k=0;
for(int i=0; i<j; i++ )
if(s[i]>=m&&s[i]<=n&&f(s[i]))
{
if(k)
cout<<" ";
else
k=1;
cout<<s[i];
}
cout<<endl;
}
return 0;
}