CSES - HIIT Open 2016 - Results
Submission details
Task:Interesting number
Sender:LTR
Submission time:2016-05-28 14:02:14 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.08 sdetails

Code

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

bool isprime(int x)
{
	for (int i = 2; i < x; ++i) {
		if ((x % i) == 0) return false;
	}
	return true;
}

bool ispalindrome(int x)
{
	std::string s = std::to_string(x);
	for (int i = 0; i < int(s.size()) / 2; ++i) {
		if (s[i] != s[s.size() - i - 1]) return false;
	}
	return true;
}

int main()
{
	std::vector<int> S;
	for (int i = 2; i < 1000; ++i) {
		if (isprime(i) && ispalindrome(i)) 
			S.push_back(i);
	}

	int t;
	std::cin >> t;
	for (int ti = 0; ti < t; ++ti) {
		int n;
		std::cin >> n;
		std::vector<int> vals;
		for (int ni = 0; ni < n; ++ni) {
			int x;
			std::cin >> x;
			vals.push_back(x);
		}
		for (int x : vals) {
			if (std::binary_search(S.begin(), S.end(), x)) {
				std::cout << x << std::endl;
				break;
			}
		}
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
9
300 988 956 931 116 3 386 202 ...

correct output
3
3
181
919
191
...

user output
3
3
181
919
191
...

Test 2

Verdict: ACCEPTED

input
1
100000
72 247 605 249 10 422 594 490 ...

correct output
191

user output
191