Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		n, _ := strconv.Atoi(buf[0])
		x, _ := strconv.Atoi(buf[1])
		prime_table := make([]int, 1000001)
		prime_table[0] = -1
		prime_table[1] = -1
		for i := 2; i < 1000001; i++ {
			if ^prime_table[i] != 0 {
				prime_table[i] = 1
				for j := 2*i; j < 1000001; j += i {
					prime_table[j] = -1 // -1 means "not prime"
				}
			}
		}
		dp := make([]int, x+1)
		dp[0] = 1
		menu := make([]int, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			menu[i], _ = strconv.Atoi(scanner.Text())
		}
		for i := 0; i < n; i++ {
			for j := 0; j <= x; j++ {
				if menu[i] <= j && dp[j-menu[i]] != 0 {
					// log.Println(dp)
					dp[j] = 1
				}
			}
		}
		flag := true
		for j := x; j >= 0; j-- {
			if prime_table[j] == 1 && dp[j] == 1 {
				flag = false
				fmt.Println(j)
				break
			}
		}
		if flag {
			fmt.Println("NA")
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
using namespace std;
typedef pair<int,int> P;
const int INF = ~(1<<31) / 2;

bool is_prime[1000001];
int max_able_num[1000001];
int max_able_prime[1000001];
int price[30];

int main(){
    is_prime[1] = false; is_prime[0] = false;
    fill(is_prime,is_prime+1000001,true);
    for(int i=2;i<=1000000;i++){
        if(is_prime[i]){
            for(int j=2;j*i<=1000000;j++){
                is_prime[j*i] = false;
            }
        }
    }

    while(1){
        int n, x;
        scanf("%d %d",&n,&x);
        if(n==0) break;

        for(int i=0;i<n;i++){
            scanf("%d",&price[i]);
        }

        fill(max_able_num,max_able_num+x+1,-1);
        max_able_num[0] = 0;
        for(int i=0;i<=x;i++){
            if(max_able_num[i]>=0){
                for(int j=0;j<n;j++){
                    if(i+price[j]<=x){
                        max_able_num[i+price[j]] = i+price[j];
                    }
                }
            }else{
                max_able_num[i] = max_able_num[i-1];
            }
            //printf("%d %d\n",i,max_able_num[i]);
        }
        max_able_prime[0] = 0;
        for(int i=1;i<=x;i++){
            if(is_prime[max_able_num[i]]){
                max_able_prime[i] = max_able_num[i];
            }else{
                max_able_prime[i] = max_able_prime[i-1];
            }
            //printf("%d %d\n",i,max_able_prime[i]);
        }
        if(max_able_prime[x])cout << max_able_prime[x] << endl;
        else cout << "NA" << endl;

        /*
        priority_queue <int> que;
        que.push(max_able_num[x]);
        fill(checked,checked+x+1,false);
        checked[max_able_num[x]] = true;
        bool found = false;

        while(que.size()){
            int p = que.top(); que.pop();
            cout << p << endl;
            if(is_prime[p]){
                found = true;
                cout << p << endl;
                break;
            }
            for(int i=0;i<n;i++){
                int next_p = p-price[i];
                if(!checked[next_p] && next_p>=0){
                    checked[next_p] = true;
                    que.push(next_p);
                }
            }
        }

        if(!found){
            cout << "NA" << endl;
        }
        */
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
#define MAX_N 1000001

int prime[MAX_N];
bool is_prime[MAX_N];

int main(){
  int p = 0;
  for(int i=0;i<=MAX_N;i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<=MAX_N;i++){
    if(is_prime[i]){
      prime[p++] = i;
      for(int j=2*i;j<=MAX_N;j+=i) is_prime[j] = false;
    }
  }

  int n,x;
  while(cin >> n >> x){
    if(n==0&&x==0) break;
    int v[n];
    bool dp[x+1];
    for(int i=0;i<=x;i++)
      dp[i] = false;

    for(int i=0;i<n;i++)
      cin >> v[i];
    dp[v[0]] = true;

    for(int i=0;i<n;i++){
      for(int j=0;j<=x-v[i];j++){
        if(dp[j]) dp[j+v[i]] = true;
      }
    }
    for(int i=x;i>=0;i--){
      if(i==0) cout << "NA" << endl;
      if(dp[i]&&is_prime[i]){
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

C++: // 2012/11/19 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[1000001];

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<=1000000; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<=1000000; i++){
		if(is_prime[i]){
			for(int j=i*i; j<=1000000; j+=i){
				is_prime[j] = false;
			}
		}
	}

	while(true){
		int n, x;
		cin >> n >> x;

		if(n==0&&x==0)
			break;

		int K[30];
		for(int i=0; i<n; i++){
			cin >> K[i];
		}

		bool dp[1000001];

		dp[0] = true;
		for(int i=1; i<=x; i++){
			dp[i] = false;
		}

		for(int i=0; i<n; i++){
			for(int j=K[i]; j<=x; j++){
				if(!dp[j]&&dp[j-K[i]]){
					dp[j] = true;
				}
			}
		}

		int ans = -1;
		for(int i=x; i>=2; i--){
			if(is_prime[i]&&dp[i]){
				ans = i;
				break;
			}
		}

		if(ans!=-1){
			cout << ans << endl;
		}
		else{
			cout << "NA" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,ans,u[100];vector<vector<int> > ad;
void dfs(int c,int m){
	if(ans<m)ans=m;
	rep(i,ad[c].size())if(!u[ad[c][i]]){
		u[ad[c][i]]=1;dfs(ad[c][i],m+1);u[ad[c][i]]=0;
	}
}
int main(){
	while(cin>>n,n){
		ad.clear();ad.resize(100);
		rep(i,n){
			int a,b; cin>>a>>b; a--,b--;
			ad[a].push_back(b),ad[b].push_back(a);
		}
		ans=1;rep(i,100)u[i]=0;
		rep(i,100)if(!ad[i].empty()){
			u[i]=1;dfs(i,1);u[i]=0;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,ans,u[100];vector<vector<int> > ad;
void dfs(int c,int m){
	if(ans<m)ans=m;
	rep(i,ad[c].size())if(!u[ad[c][i]]){
		u[ad[c][i]]=1;dfs(ad[c][i],m+1);u[ad[c][i]]=0;
	}
}
int main(){
	while(cin>>n,n){
		ad.clear();ad.resize(100);
		rep(i,n){
			int a,b; cin>>a>>b; a--,b--;
			ad[a].push_back(b),ad[b].push_back(a);
		}
		ans=1;rep(i,100)u[i]=0;
		rep(i,100)if(!ad[i].empty()){
			u[i]=1;dfs(i,1);u[i]=0;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }

deque<bool> enum_prime(ll N){
	deque<bool> is_prime(N+1,true);
	is_prime[0]=is_prime[1]=false;
	for(ll i=2;i<=N;i++){
		if(is_prime[i]){
			for(ll j=i*i;j<=N;j+=i){
				is_prime[j] = false;
			}
		}
	}
	return is_prime;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto P = enum_prime(1000000);

	while(true){
		int N=in(),X=in();
		if(!N && !X) break;
		auto V=vecin(N);
		vector<int> dp(X+1,0);
		dp[0]=1;
		int ans=-1;
		REP(j,X+1){
			REP(i,N){
				if(j+V[i]<=X){
					chmax(dp[j+V[i]],dp[j]);
				}
			}
			if(dp[j] && P[j]){
				ans = j;
			}
		}
		
		if(ans<0) out("NA");
		else out(ans);
	}

	return 0;
}