Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 15:25:28
2016-05-28 11:32:31
2016-05-28 11:21:32
Task:Interesting number
Sender:Barely Div 1
Submission time:2016-05-28 11:32:31
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;


bool ok(int i) {
	if (i == 1) return false;
	string s = to_string(i);
	string s2 = s;
	reverse(s2.begin(), s2.end());
	if (s != s2) return false;
	if (i <= 2) return true;
	for (int j = 2; j < i; j++) {
		if ((i % j) == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t; cin >> t;
	vector<bool> oks(1001);
	for (int i = 1; i<=1000; i++) {
		if (ok(i)) oks[i] = true;
	}
	while (t--) {
		int n; cin >> n;
		while (n--) {
			int num; cin >> num;
			if (oks[num]) {
				cout << num << "\n";
			}
		}

	}


}