View Code of Problem 92

#include<bits/stdc++.h>
using namespace std;
int both(int x){
	int a[1000],k =0;
	for(int i = 2; i <= sqrt(x);i++){
		if(x%i == 0){
			return 0;
		}
	}
	while(x>0){
		a[k++]=x%10;
		x/=10;
	}
	for(int i =0,j=k-1; i < j; i++,j--){
		if(a[i]!=a[j]){
			return 0;
		}
	}
	return 1;
}
int main(){
	int m,n,k = 0;
	int num[1000];
	cin>>m>>n;
	for(int i = m; i <= n; i++){
		if(both(i)==1){
			num[k++] = i;
		}
	}
	int cnt = 0;
	for(int i = 0; i < k; i++){
		cnt++;
		if(cnt!=5){
			printf("%6d",num[i]);
		}else{
			printf("%6d\n",num[i]);
			cnt = 0;
		}
	}
}

Double click to view unformatted code.


Back to problem 92