View Code of Problem 92

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int f(int a){
	string s=std::to_string(a);
	int i,n=s.size();
	for(i=0;i<(n/2);i++){
		if(s[i]!=s[n-1-i])
			break;
	}
	if(i>=n/2)	return 1;
	else return 0;
}
int g(int a){
	int i;
	for(i=2;i<=sqrt(a);i++){
		if(a%i==0)	break;
	}
	if(i>sqrt(a))	return 1;
	else return 0;
}


int main(){
	int m,n,j=0;
	cin>>m>>n;
	for(int i=m;i<=n;i++){
		if(f(i)==1){
			if(g(i)==1){
				printf("%6d",i);
				j++;	
			}
		}
		if(j==5){
			j=0;cout<<endl;
		}
	}
} 

Double click to view unformatted code.


Back to problem 92