View Code of Problem 92

#include<bits/stdc++.h>
using namespace std;
int a[10005];
int h[1000];
int m,n,i,j,cnt;

int fun(int n) {
	int m=n;
	int x=0;
	do{
		x*=10;
		x+=m%10;
		m/=10;
	}while(m>0);
	if(x==n)
		return 1;
	else 
		return 0;
}
int main()
{
	for(i=0;i<10005;i++)
		a[i] = 1;
		
	for(i=2;i<10005;i++)
		for(j=2;i*j<10005;j++)
			a[i*j] = 0;
	
//	cout<<fun(11);
while(cin>>m>>n) {
		j=0;
		for(i=m;i<=n;i++) 
			if(a[i] && fun(i)) {
				h[j++] = i;
			}
		for(i=0;i<j;i++) {
			if(i%5==0&&i!=0) 
				printf("\n");
			printf("%6d",h[i]);
		}
		printf("\n");		
	}
			
	
	
	return 0;
}

Double click to view unformatted code.


Back to problem 92