CSES - HIIT Open 2016 - Results
Submission details
Task:Interesting number
Sender:Noname 01
Submission time:2016-05-28 11:09:51 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.06 sdetails
#20.05 sdetails

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;
 for (i = 1; i <= 1000; i++) {
	int ii = int(sqrt(i+0.0))+1;
	for (j = 2; j < ii; 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;
}

Test details

Test 1

Verdict:

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:

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

correct output
191

user output
1