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])
		if n == 0 && x == 0 {
			break
		}
		prime_table := make([]int, 1000001)
		prime_table[0] = -1
		prime_table[1] = -1
		for i := 2; i < 1000001; i++ {
			if prime_table[i] != -1 {
				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<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 1000009
/*void dfs(int num){
    if(flag) return;
    if(ans==num){flag=true;return;}
    if(num>ans){memo[num]=false;return;}
    else rep(i,n){
        cout<<num<<endl;
      if(num+v[i]<=ans&&memo[num+v[i]])dfs(num+v[i]);
    }
    memo[num]=false;
    return;
}*/
int main(){
    vector<bool>check(MAX+1);  //index number will be checked
    rep(i, MAX+1)check[i] = true;
    vector<int>Primenumber(MAX+1,0); //Primearray
    int counter =0;                  //Primearray counter;
    for(int i = 2; i<MAX+1;i++){
        if(check[i]){
            for(int j = 2;i*j<MAX;j++)
                check[i*j] = false;//?´???°??????Primearray???????´??????????????????°?????¨???false???
            Primenumber[counter] = i;
            counter++;
        }
    }
    int m,n,ans; bool flag;
    while(cin>>n>>m,n+m){
        vi v;
        int temp;
        flag=false;
        rep(i,n){cin>>temp; v.push_back(temp);}
        for(int i=m;i>=2;i--){
            if(check[i]){
                ans=i;break;}
        }
        bool array[MAX]; rep(i,MAX)array[i]=false;
        rep(i,n)array[v[i]]=true;
        for(int i=2;i<=ans;i++) {
            if(array[i])rep(j,n)if(i+v[j]<=ans)array[i+v[j]]=true;
            if(array[ans])break;
        }
        if(array[ans]) cout<<ans<<endl;
        else cout<<"NA"<<endl;
    }
}

C++: #include <iostream>
#include <string.h>
using namespace std;

bool prime[1000001];
void is_prime(int n){
	for(int i = 0; i <= n; ++i)
		prime[i] = true;
	prime[0] = prime[1] = false;
	
	for(int i = 2; i <= n; ++i){
		if(prime[i]){
			for(int j = i * 2; j <= n; j += i)
				prime[j] = false;
		}
	}
}

int memo[1000001];
int N, X, cook[50], ans;

int rec(int w){
	if(memo[w] != -1)
		return memo[w];
	if(X - w < 0)
		return 0;
	if(prime[X - w])
		ans = max(ans, X - w);
	int res = 0;
	for(int i = 0; i < N; ++i){
		if(w - cook[i] >= 0)
			res = max(res, rec(w - cook[i]));
	}
	return memo[w] = res;
}

int main() {
	is_prime(1000000);
	while(cin >> N >> X && (N || X)){
		ans = 0;
		memset(memo, -1, sizeof(memo));
		
		for(int i = 0; i < N; ++i)
			cin >> cook[i];
			
		rec(X);
		if(ans == 0)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}
	
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;

int T;
const int MAXT = 30;
int X;
const int MAXX = 1000000;
vector<bool> Prime(MAXX+1, true);

int main(void) {
	// calc prime
	int sq_n = (int)(sqrt((double)MAXX) + 0.9);
	Prime[0] = false;
	Prime[1] = false;
	for (int i = 2; i < sq_n; i++) {
		if (Prime[i]) {
			for (int j = i + i; j < MAXX; j += i) {
				Prime[j] = false;
			}
		}
	}

	while (cin >> T >> X, T || X) {
		// input and init
		vector<int> price(T);
		vector<bool> dp(X+1, false);
		for (int i = 0; i < T; i++) {
			cin >> price[i];
			dp[price[i]] = true;
		}

		// dp
		for (int i = 0; i <= X; i++){
			if (!dp[i]){
				continue;
			}
			for (int j = 0; j < T; j++) {
				int x = i + price[j];
				if (x <= X) {
					dp[x] = true;
				}
			}
		}

		int res = 0;
		for (int i = X; i >= 0; i-- ){
			if (dp[i] && Prime[i]){
				res = i;
				break;
			}
		}

		// output
		if (res){
			cout << res << endl;
		}else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
using namespace std ;
void ans( int cnt ,int dp[] )
{
	int a = cnt + 1 ;
	LOOK :
	a-- ;
	while( dp[ a ] != 1 )
	{
		a-- ;
		if( a < 2 )
		{
			END :
			cout << "NA" << endl ;
			return ;
		}
	}
	if( a < 2 )
	{
		goto END ;
	}
	if( a % 2 == 0 )
	{
		goto LOOK ;
	}
	if( a == 2 )
	{
		cout << a << endl ;
		return ;
	}
	for( int i = 3 ; i * i <= a ; i += 2 )
	{
		if( a % i == 0 )
		{
			goto LOOK ;
		}
	}
	cout << a << endl ;
	return ;
}
int main()
{
	int n ,m ;
	int dmon[ 30 ] ;
	int j ;
	while( cin >> n >> m )
	{
		if( n== 0 && m == 0 )
		{
			break ;
		}
		int cnt = m ;
		long long dp[ 1000000 + 1 ] = { 0 } ;
		for( int i = 0 ; i < n ; i++ )
		{
			cin >> dmon[ i ] ;
		}
		for( int i = 0 ; i + dmon[ 0 ] <= m ; )
		{
			for( j = 0 ; j < n && i + dmon[ j ] <= m ; j++ )
			{
				dp[ i + dmon[ j ] ] = 1 ;
			}
			i++ ;
			while( dp[ i ] != 1 )
			{
				i++ ;
			}
		}
		ans( cnt ,dp ) ; 
	}
	return 0 ;
}

C++: #include<bits/stdc++.h>
using namespace std;
bool sosu[1000005]={0};
bool check[1000005];
main(){
????int n,k;
????int shop;
????sosu[1]=1;
????for(int i=2;i<(int)sqrt(1000005);i++){
????????if(sosu[i]==0){
????????????for(int j=i;j<1000005;j+=i){
????????sosu[j]=true;
????????????}
????????}
????}
????while(1){
????????bool a=true;
????????cin>>n>>k;
????????if(n==0&&k==0)break;
????????memset(check,false,sizeof(check));
????????for(int i=1;i<=n;i++){
????????????scanf("%d",&shop);
????????????check[shop]=true;
????????????for(int j=shop;j<=k;j++){
????????if(check[j-shop]==true){
????????????check[j]=true;
????????}
????????????}?? 
????????}
????????for(int i=k;i>0;i--){
????????????if(sosu[i]==false&&check[i]==true){
????????cout<<i<<endl;
????????i=0;
????????a=false;
????????????} 
????????}
????????if(a){
????????????cout<<"NA"<<endl;
????????}
????}
}

C++: #include<iostream>
#include<utility>
#include<queue>
#include<functional>
#include<cstring>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define ALL(x) (x).begin(),(x).end()
typedef pair<int,int> pii;
typedef vector<int> vi;

const int M=1010000;
vi pri;
int pf[M]={1,1};

void calc_pri()
{
	FORI(i,2,M)
	{
		if(!pf[i])
		{
			pri.push_back(i);
			for(int j=i+i;j<M;j+=i)
			{
				pf[j]=1;
			}
		}
	}
}	



int a[M];

int main()
{
	calc_pri();
	int x,n;
	while(cin>>n>>x&&n)
	{
		FOR(i,M)a[i]=0;
		a[0]=1;
		FOR(i,n)
		{
			int k;cin>>k;
			FOR(j,M)
			{
				if(j+k>=M)break;
				if(a[j])a[j+k]=1;
			}
		}
		for(int i=x;i>=0;i--)
		{
			if(i==0)cout<<"NA"<<endl;
			if(a[i]&&!pf[i])
			{
				cout<<i<<endl;
				break;
			}
		}
	}
	
}