View Code of Problem 92

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
int issu(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0) {
			return 0;
			break;
		}
	}
	return 1;
}
string change(int n) {
	string s;
	int i = 0;
	while (n)
	{
		s+= (n % 10)+'0';
		//cout << s;
		n = n / 10;
	}
	return s;
}
//int ishui(string s) {
//
//}
int main()
{
	int m, n;
	cin >> m >> n;
	string s;
	string s1;
	int flag = 1;
	for (int i = m; i <= n; i++) {
		s = change(i);
		s1 = change(i);
		reverse(s.begin(), s.end());
		//cout << issu(n);
		if (s == s1 && issu(i)) {
			if (flag < 5) {
				cout <<setw(6)<< i ;
				flag++;
			}
			
			else if (flag == 5) {
				cout << setw(6) << i<<endl;
				flag = 1;
			}
		}
	}

}

Double click to view unformatted code.


Back to problem 92