Skip to content

Instantly share code, notes, and snippets.

@plantvsbirds
Created October 27, 2014 04:59
Show Gist options
  • Save plantvsbirds/b81f7d8a4486144cff00 to your computer and use it in GitHub Desktop.
Save plantvsbirds/b81f7d8a4486144cff00 to your computer and use it in GitHub Desktop.
#include <iostream>
#define MAX 1000000-1
using namespace std;
int do_1(int c){
cout << "Case #" << c<<": ";
bool table[1000000];
long long data[101];
for (int i=0;i<=(MAX);i++) {
table[i] = true;
}
int max = 0;
int sq = 0;
cin >> sq;
bool quit = false;
for (int i=1;i<=(sq);i++) {
int num = 0;
cin >> num;
max = max > num ? max : num;
data[i] = num;
if (num == 1) {
quit = true;
}
}
if (quit){
cout << "NO" << endl;
return 0;
}
int dead = 0;
for (int i=1;i<=(sq);i++) {
int num = data[i];
for (int j=2;j<=(num-1);j++) {
if (num % j != 0)
table[j] = false;
}
if (!dead) {
for (int j=num+1;j<=max;j++) {
table[j] = false;
}
dead = num+1;
} else {
for (int j=num+1;j<=dead;j++) {
table[j] = false;
}
}
}
for (int i=2;i<=(max-1);i++) {
if (table[i]) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
int main (){
int cases = 0;
cin >> cases;
for (int c=1;c<=cases;c++) {
int res = do_1(c);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment