Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define Size 20000
- int Set(int N,int pos){
- return N = N | (1<<pos);
- }
- bool Check(int N,int pos){
- return (bool)(N & (1<<pos));
- }
- bool mark[Size];
- vector <int> primeList;
- void seive(){
- memset (mark, true, sizeof (mark));
- mark [0] = mark [1] = false;
- for(int i = 4;i<Size;i+=2) mark [i] = false;
- for(int i=3;i*i<=Size;i+=2){
- if(mark[i]){
- for(int j=i*i;j<Size;j+=2*i)
- mark [j] = false;
- }
- }
- primeList.clear ();
- primeList.push_back (2);
- for(int i=3;i<Size;i+=2){
- if(mark[i]){
- primeList.push_back (i);
- }
- }
- }
- int L = 14;
- bool f[15];
- int N,num,last;
- vector<int> Graph[15];
- bool found = false;
- void call(int cnt,int val){
- if(val == num){
- found = true;
- return;
- }
- if(cnt > 4) return;
- for(int i = 0;i<15;i++){
- if(Check(val,i) == false && f[i] == true){
- int Sz = Graph[i].size();
- int nVal = val;
- for(int c = 0;c<Sz;c++){
- int adj = Graph[i][c];
- call(cnt+1,nVal | adj);
- if(found == true) return;
- }
- }
- }
- }
- int main() {
- seive();
- int last = primeList.size();
- cin >> N;
- for(int i = 0;i<N;i++){
- cin >> num;
- memset(f,false,sizeof(f));
- for(int i = 0;i<15;i++){
- if(Check(num,i) == true){
- f[i] = true;
- }
- Graph[i].clear();
- }
- for(int i = 0;i<last;i++){
- int cur = primeList[i];
- bool ok = true;
- for(int c = 0;c<15;c++){
- if(Check(cur,c) == true && f[c] == false){
- ok = false;
- break;
- }
- }
- if(ok == true){
- for(int c = 0;c<15;c++){
- if(Check(cur,c) == true){
- Graph[c].push_back(cur);
- }
- }
- }
- }
- found = false;
- call(0,0);
- if(found == true){
- cout << "YES" << endl;
- }else{
- cout << "NO" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment