CSES - HIIT Open 2016 - Results
Submission details
Task:Interesting number
Sender:Oispa Kaljaa
Submission time:2016-05-28 11:35:31 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#20.13 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:31:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < is.length()/2; j++){
                                    ^

Code

#include <bits/stdc++.h>

using namespace std;

string ints(int n){
  stringstream ss;
  ss << n;
  return ss.str();
}  
int main(){
  cin.sync_with_stdio(0);
  cin.tie(0);
  int tests; cin >> tests;
  int prim[1010] = {0};
  prim[2] = 1;
 
  for(int i = 3; i <= 1000; i+=2){
      bool g = true;
      for(int j = 2; j < i ; j++){
	  if(i%j == 0){
	    g = false;
	    break;
	  }
      }
      prim[i] = g;
  }
  map<string, bool> pal;
  for(int i = 1; i <= 1000; i++){
    string is = ints(i);
    bool g = true;
    for(int j = 0; j < is.length()/2; j++){
	if(is[j] != is[is.length()-1-j])
	  g = false;
    }
    
    pal[is] = g;
  }

  while(tests--){
      int n; cin >> n;
      int a[1010];
      for(int i = 0; i < n; i++){
	cin >> a[i];
	
      }
      for(int i = 0; i < n; i++){
	if(prim[a[i]] && pal[ints(a[i])]){
	    cout << a[i] << endl;
	    break;
	}
      }
	
  }
  return 0;
}

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:

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

correct output
191

user output
(empty)