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 11:27:15
2016-05-28 11:12:22
2016-05-28 11:09:51
Task:Interesting number
Sender:Noname 01
Submission time:2016-05-28 11:27:15
Status:READY
Result:ACCEPTED

Show test data

Code

// NONAME-01

#include <bits/stdc++.h>


using namespace std;

vector <int> a;
int pr[1001];
int pal[1001];

void Load()
{
  int n;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++)
	 cin >> a[i];
}

void Solve()
{
  int i;
  for (i = 0; i < (int)a.size(); i++) {
	if (pr[a[i]] == 1 && pal[a[i]] == 1) {
		cout << a[i] << "\n";
		break;
	}
  }
}

void Fill() {
 int i, j;
 pr[1] = 0;
 for (i = 2; i <= 1000; i++) {
	for (j = 2; j*j <= i && j < i; j++) {
		if (i % j == 0) {
			pr[i] = -1;
			break;
		}
	}
	pr[i]++;
	if (i < 10) {
	  pal[i] = 1;
	} else if (i < 100) {
		if (i % 10 == i/10) pal[i] = 1;
	} else if (i < 1000) {
		if (i%10 == i / 100) pal[i] = 1;
	}
 }
}

int main() {
  Fill();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int nt, tt;
  cin >> nt;
  for (tt = 0; tt < nt; tt++) {
	Load();
	Solve();
  }
  return 0;
}