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:31:40
Task:Interesting number
Sender:Team Purkka
Submission time:2016-05-28 11:31:40
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define ll long long

using namespace std;
bool in[1001];
int main () {
  string s;
  in[1]=1;
  in[2]=0;
  for(int i=4;i<=1000;i+=2)in[i]=1;
  for(int i=3;i<=1000;i+=2){
    if(!in[i]){
      for(int j=i*2;j<=1000;j+=i){
	in[j]=1;
      }
    }
  }
  for(int i=3;i<=1000;i++){
    int d3=i/1000,d2=i/100%10,d1=i/10%10,d0=i%10;
    if(!((d3==d0&&d2==d1)||(i<1000&&d2==d0)||(i<100&&d1==d0)||(i<10))){
      in[i]=1;
    }
  }
  int t;
  int k;
  int n;
  cin>>t;
  for(int i=0;i<t;i++){
    cin>>n;
    for(int j=0;j<n;j++){
      cin>>k;
      if(!in[k]){
	cout<<k<<endl;
      }
    }
  }
}